Skip to content

avoid out-of-range double to long long casts in MSBuild System.Math - #8950

Open
Nussu06 wants to merge 1 commit into
cppcheck-opensource:mainfrom
Nussu06:msbuild-math-float-cast
Open

Nussu06 wants to merge 1 commit into
cppcheck-opensource:mainfrom
Nussu06:msbuild-math-float-cast

Conversation

@Nussu06

@Nussu06 Nussu06 commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

fmtDouble and the Round branch in ImportProject::applyMSBuildStaticFunction cast the double result of a System.Math property function to long long without a range check, so a project value like $([System.Math]::Pow(10,30)) or $([System.Math]::Round(1e30)) is undefined behaviour (UBSan float-cast-overflow, as noted in the AI review on #8938). fmtDouble now takes the integer path only when the value fits in long long, and Round does its half-to-even step in double and formats through fmtDouble, so in-range results are unchanged and Round(1e30) gives the same text as Pow(10,30) instead of LLONG_MIN (out-of-range values still print via std::to_string rather than MSBuild's 1E+30, which is left for a separate change). Tested with new asserts in testMSBuildStaticFunctions, the full testrunner, and cppcheck --project on a crafted vcxproj with a UBSan build. I don't have Trac access, so could you create a ticket for this one?

@dmcppcheck

Copy link
Copy Markdown

There should probably be a trac ticket for this PR. Please create it, or ask us to create it. Then the PR title should be updated.

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.

2 participants