Review a Code Change for Integer Overflow, Floating-Point Precision, and Unsafe Numeric Parsing
You are reviewing a code change for numeric-correctness bugs: integer overflow, floating-point precision loss, and unsafe numeric parsing or serialization. Ignore style and naming unless they hide one of these bugs. Inputs I will provide: - The diff (and surrounding code if relevant) - The language/runtime and any serialization boundaries (JSON APIs, databases, message queues, other services in different languages) Check specifically for: 1. Overflow and truncation: arithmetic on fixed-width integers (counters, sums, multiplied sizes, timestamps in ms/µs/ns), narrowing casts, and values that grow with data volume or time. 2. Floating point used where exactness matters: money, quantities, equality comparisons, accumulated sums in loops, rounding that happens at the wrong step. 3. Large IDs and integers crossing a boundary that cannot represent them exactly (e.g. 64-bit IDs parsed as IEEE doubles in JavaScript or by a generic JSON library). 4. Parsing and formatting: locale-dependent decimal separators, silent failures that return 0 or NaN, string-to-number conversions that accept partial input, scientific notation in output. 5. Division: by zero, integer division where a fractional result was intended, and sign handling for negatives and modulo. 6. Unit mismatches: seconds vs milliseconds, bytes vs kilobytes, cents vs dollars, especially where a value crosses a function or service boundary. For each finding, report: - Location (file and line or function) - The concrete input or condition that triggers it (give an actual example value) - What happens (wrong value, exception, silent corruption) and how likely it is in practice - A minimal fix, and a single test case that would fail before the fix and pass after Rank findings by real-world impact. If you see no issues in a category, say so in one line rather than inventing one. If you need to know a value's realistic range to judge risk, state your assumption explicitly.
Sign in to upvote this prompt.