Skip to content

Commit

Permalink
Fix integer overflow microsoft#2357
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-smith-zocdoc committed Sep 11, 2019
1 parent b310fb4 commit 22a0675
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/io/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,21 @@ void Config::CheckParamConflict() {
}
// Check max_depth and num_leaves
if (max_depth > 0) {
int full_num_leaves = static_cast<int>(std::pow(2, max_depth));
double full_num_leaves = std::pow(2, max_depth);
if (full_num_leaves > num_leaves
&& num_leaves == kDefaultNumLeaves) {
Log::Warning("Accuracy may be bad since you didn't set num_leaves and 2^max_depth > num_leaves");
}
num_leaves = std::min(num_leaves, 2 << max_depth);

const int MAX_LEAVES = 2 << 16;
if (num_leaves > MAX_LEAVES) {
Log::Fatal("num_leaves (%d) is larger than maximum allowed leaves (%d)", num_leaves, MAX_LEAVES);
}

if (full_num_leaves < MAX_LEAVES && full_num_leaves < num_leaves) {
// Fits in an int, and is more restrictive than the current num_leaves
num_leaves = static_cast<int>(full_num_leaves);
}
}
}

Expand Down

0 comments on commit 22a0675

Please sign in to comment.