Skip to content

Fix #15299: internalError with float conversion - #9105

Merged
ludviggunne merged 3 commits into
cppcheck-opensource:mainfrom
ludviggunne:15299-float-conv
Dec 3, 2026
Merged

ludviggunne merged 3 commits into
cppcheck-opensource:mainfrom
ludviggunne:15299-float-conv

Conversation

@ludviggunne

Copy link
Copy Markdown
Collaborator

No description provided.

@dmcppcheck dmcppcheck left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review

I found no problems. The PR fixes the internalError that occurs when a NaN or ±inf float value reaches Library::isFloatArgValid. Range specs already reject NaN and accept inf where the range allows it. Single values and !value specs no longer hand inf.0/nan.0 strings to MathLib::toDoubleNumber. The message now prints nan the same way on every libc, instead of nan on one and -nan on another. The new test covers NaN and +inf.

Testing

  • I built cppcheck and testrunner in pr/ and cppcheck in base/. Both builds succeeded.

  • ./testrunner TestFunctions: 62 tests ran and 0 failed.

  • I wrote scratch files that produce non-finite values through value flow and pass them to library functions with float valid ranges:

    • asin, acos, log, log10 and sqrt with +inf, -inf, NaN and -NaN.
    • fmod(1.0, x), whose valid spec is !0.0, with inf, -inf and NaN.

    For example:

    void f1() { double c = 1e300; c = -c * c; c = asin(c); }
    void g1() { double c = 1e300; c = c*c; double r = fmod(1.0, c); (void)r; }

    On these files base gives error: Internal Error. MathLib::toDoubleNumber: conversion failed: -inf.0 [internalError] (and inf.0 for the fmod file).

    The PR gives these results:

    • Invalid asin() argument nr 1. The value is -inf ..., and the same for sqrt(-inf) and log10(-inf).
    • The value is nan ... for NaN and -NaN arguments to asin, acos, log and sqrt.
    • No warning for sqrt(inf), log(inf) or fmod(1.0, inf/nan), which is correct.
    • No internal errors.

Automated review of 48863a1 by Claude. The pull request was built and tested locally.

@ludviggunne
ludviggunne merged commit 07b525d into cppcheck-opensource:main Dec 3, 2026
74 of 77 checks passed
@ludviggunne
ludviggunne deleted the 15299-float-conv branch December 3, 2026 14:58
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.

3 participants