Modelling - Fixed crash in ComputePolesIndexes() (#1049)

- Replaced partial bound checks with `std::clamp()` to validate both bounds for `theOutMinIdx` and `theOutMaxIdx`
- Renamed local variable `mult` to `aMultiplier` for better clarity
This commit is contained in:
Dmitrii Kulikov
2026-02-05 13:32:43 +00:00
committed by GitHub
parent fca1b3e0c3
commit f159fc0933

View File

@@ -222,17 +222,17 @@ void ComputePolesIndexes(const NCollection_Array1<double>& theKnots,
int& theOutMaxIdx)
{
BSplCLib::Hunt(theKnots, theMin, theOutMinIdx);
theOutMinIdx = std::max(theOutMinIdx, theKnots.Lower());
theOutMinIdx = std::clamp(theOutMinIdx, theKnots.Lower(), theKnots.Upper());
BSplCLib::Hunt(theKnots, theMax, theOutMaxIdx);
theOutMaxIdx++;
theOutMaxIdx = std::min(theOutMaxIdx, theKnots.Upper());
int mult = theMults(theOutMaxIdx);
theOutMaxIdx = std::clamp(theOutMaxIdx, theKnots.Lower(), theKnots.Upper());
const int aMultiplier = theMults(theOutMaxIdx);
theOutMinIdx = BSplCLib::PoleIndex(theDegree, theOutMinIdx, theIsPeriodic, theMults) + 1;
theOutMinIdx = std::max(theOutMinIdx, 1);
theOutMaxIdx = BSplCLib::PoleIndex(theDegree, theOutMaxIdx, theIsPeriodic, theMults) + 1;
theOutMaxIdx += theDegree - mult;
theOutMaxIdx += theDegree - aMultiplier;
if (!theIsPeriodic)
theOutMaxIdx = std::min(theOutMaxIdx, theMaxPoleIdx);
}