Skip to content

Commit

Permalink
remove potential pointer access issue in Flatten function
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbkoch committed Dec 25, 2024
1 parent 15cb6fb commit 2f70efa
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions shared/libebm/PartitionOneDimensionalBoosting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ static ErrorEbm Flatten(BoosterShell* const pBoosterShell,
FloatScore* const aUpdateScore = pInnerTermUpdate->GetTensorScoresPointer();
FloatScore* pUpdateScore;

UIntSplit prev = 0;
const Bin<FloatMain, UIntMain, true, true, bHessian>* const* ppBinCur = nullptr;
if(bNominal) {
UIntSplit iSplit = 1;
Expand All @@ -177,6 +178,7 @@ static ErrorEbm Flatten(BoosterShell* const pBoosterShell,
// always put a split on the missing bin
*pSplit = 1;
++pSplit;
prev = 1;

// pUpdateScore is overwritten later if bNominal
pUpdateScore += cScores;
Expand Down Expand Up @@ -265,7 +267,8 @@ static ErrorEbm Flatten(BoosterShell* const pBoosterShell,
++iEdge; // missing is at index 0 in the model, so we are offset by one
pMissingBin = pTreeNode->GetBin();
EBM_ASSERT(iEdge <= cBins + 1);
if(cBins + 1 == iEdge && cBins == *(pSplit - 1)) {
EBM_ASSERT(0 != prev);
if(cBins + 1 == iEdge && cBins == prev) {
// this cut would isolate the missing bin, but we handle those scores separately
break;
}
Expand Down Expand Up @@ -368,7 +371,8 @@ static ErrorEbm Flatten(BoosterShell* const pBoosterShell,
}

EBM_ASSERT(!IsConvertError<UIntSplit>(iEdge));
*pSplit = static_cast<UIntSplit>(iEdge);
prev = static_cast<UIntSplit>(iEdge);
*pSplit = prev;
++pSplit;

break;
Expand Down

0 comments on commit 2f70efa

Please sign in to comment.