Unverified Commit 0012fc28 authored by Philip Hyunsu Cho's avatar Philip Hyunsu Cho Committed by GitHub
Browse files

Fix undefined behavior with NaN input in `CategoricalDecision()` (#4468)

* Fix undefined behavior with NaN input in CategoricalDecision()

* Always associate the right child with NaN inputs
parent 5b7a6f3e
...@@ -366,16 +366,14 @@ class Tree { ...@@ -366,16 +366,14 @@ class Tree {
} }
inline int CategoricalDecision(double fval, int node) const { inline int CategoricalDecision(double fval, int node) const {
uint8_t missing_type = GetMissingType(decision_type_[node]); int int_fval;
int int_fval = static_cast<int>(fval); if (std::isnan(fval)) {
if (int_fval < 0) { return right_child_[node];
return right_child_[node];; } else {
} else if (std::isnan(fval)) { int_fval = static_cast<int>(fval);
// NaN is always in the right if (int_fval < 0) {
if (missing_type == MissingType::NaN) {
return right_child_[node]; return right_child_[node];
} }
int_fval = 0;
} }
int cat_idx = static_cast<int>(threshold_[node]); int cat_idx = static_cast<int>(threshold_[node]);
if (Common::FindInBitset(cat_threshold_.data() + cat_boundaries_[cat_idx], if (Common::FindInBitset(cat_threshold_.data() + cat_boundaries_[cat_idx],
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment