Fix NaN handling in min-heap index calculations - #1249
Conversation
The functions didn't validate that index is a finite number. If index was NaN or Infinity, Math.floor((NaN - 1) / 2) would return NaN, causing the heap operations to fail. Added Number.isFinite() checks to default to 0 for invalid numbers.
|
Thanks for the contribution, but this doesn't fix an actual bug. If you found a real code path that produces a non-finite index (e.g. via a NaN score somewhere upstream), please include a failing test that reproduces it and a fix at the actual source of the NaN, not a defensive patch three call-sites downstream. As written, this adds dead branches with no test coverage and no reproducible bug behind it, so it isn't something a maintainer can act on. |
Overview
Fix NaN handling in min-heap index calculations in
common/src/util/min-heap.ts.Bug Description
The functions didn't validate that index is a finite number. If index was NaN or Infinity,
Math.floor((NaN - 1) / 2)would return NaN, causing the heap operations to fail.Fix
Added
Number.isFinite()checks to default to 0 for invalid numbers.Testing
No existing tests for this function, but the fix prevents runtime errors with invalid inputs.
Files Changed
common/src/util/min-heap.ts- Added NaN validationScope
This change only touches
common/which is an approved contribution area per the Contributing Guide.