Commit 1d58342
BUG: Fix divide-by-zero and integer truncation in CalculateFitError
Two bugs in CumulativeGaussianCostFunction::CalculateFitError():
1. Division by zero: if m_OriginalDataArray has zero elements, dividing
by numberOfElements is undefined behavior. Guard added to the existing
size-mismatch early return.
2. Integer truncation: `(1 / numberOfElements) * fitError` performs
integer division, yielding 0 for any numberOfElements > 1 and making
the RMSE always return 0.0. The correct RMSE formula is
sqrt(fitError / numberOfElements).
Detected by clang-22 scan-build (core.DivideZero checker).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent 9bfc81b commit 1d58342
1 file changed
Lines changed: 2 additions & 2 deletions
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
| 55 | + | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| |||
0 commit comments