Skip to content

Fix NaN handling in min-heap index calculations - #1249

Open
pavankumar-vh wants to merge 1 commit into
CodebuffAI:mainfrom
pavankumar-vh:fix/min-heap-index-validation
Open

Fix NaN handling in min-heap index calculations#1249
pavankumar-vh wants to merge 1 commit into
CodebuffAI:mainfrom
pavankumar-vh:fix/min-heap-index-validation

Conversation

@pavankumar-vh

Copy link
Copy Markdown

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 validation

Scope

This change only touches common/ which is an approved contribution area per the Contributing Guide.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant