Repository navigation
Conversation
Cast the first operand so that integer products used as allocation sizes, file offsets, and pointer offsets are computed in size_t, off_t, or the destination integer type instead of int, and so that float products consumed as double (exp, log2, sin arguments and double variables) are computed in double. Fixes 36 CodeQL cpp/integer-multiplication-cast-to-long alerts in 15 raster tools.
This was referenced Jul 14, 2026
CodeQL flagged process.c:99,102: SQR() uses the float sqrarg, so SQR(wsize) does a float multiplication that the macro's ternary then widens to double, and the (size_t) cast applied afterwards does not prevent the float overflow. wsize is an int window size, so compute the window area as (size_t)wsize * wsize instead, keeping the whole allocation size in integer/size_t math. Fixes the 2 CodeQL cpp/integer-multiplication-cast-to-long alerts this PR previously reintroduced.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes 36 CodeQL
cpp/integer-multiplication-cast-to-longalerts across 15 raster tools (all remaining raster-tool alerts for this rule except the r.sunmask cluster, which is a larger float-precision type change handled separately).Two classes, both fixed by casting the first operand so the product is computed in the consuming type (idiom from ed986f8):
G_malloc,G_fseek,n_array + row * cols * Rast_cell_size(...)), which could overflowintfor very large regions: r.basins.fill, r.distance, r.geomorphon, r.in.mat, r.in.xyz, r.param.scale, r.regression.multi, r.resamp.filter, r.resamp.stats, r.surf.fractal, r.watershed (flag_create, ramseg), r.viewshed (totalsize, memory report).floatproducts consumed asdouble(arguments toexp,log2,sin, or double variables), now computed in double: r.ros, r.texture, r.viewshed (eventlist.cpp), r.sunhours (one line insolpos00.c). These can shift results by at most one float ulp; the r.texture testsuite, which compares numeric outputs, passes unchanged.Verification: all 15 tools compile cleanly, and the six existing testsuites among them pass against nc_spm (r.watershed, r.viewshed, r.surf.fractal, r.geomorphon, r.resamp.filter, r.texture).
This is part of a larger effort to work through the open code scanning alerts, grouped into small PRs by issue type.
Written with the assistance of Claude Code.