Skip to content

tools: Fix multiplications converted to a larger type - #7708

Merged
cwhite911 merged 3 commits into
OSGeo:mainfrom
cwhite911:tools-int-mult
Aug 25, 2026
Merged

cwhite911 merged 3 commits into
OSGeo:mainfrom
cwhite911:tools-int-mult

Conversation

@cwhite911

Copy link
Copy Markdown
Contributor

Fixes 24 CodeQL cpp/integer-multiplication-cast-to-long alerts across display, general, imagery, raster3d, vector, and visualization tools. Together with #7704, #7705, and #7706 this covers all alerts for this rule except the r.sunmask and d.linegraph clusters, which involve a larger float-precision type change and are handled separately.

Same idiom as the sibling PRs (cast the first operand so the product is computed in the consuming type):

  • Integer products used as allocation sizes, memset lengths, cell counts, and offsets, which could overflow int for very large inputs: g.pnmcomp, i.fft, i.ifft, i.rectify and i.ortho.rectify reports, i.segment, r3.out.v5d, v.surf.rst and v.vol.rst disk estimates and temp-file offsets, ximgview color table.
  • int or float products consumed as double (D_text_size, floor, region bound arithmetic): d.graph, d.legend, r3.in.v5d, v.extract random selection.

Verification: all 14 tools compile cleanly, and the four existing testsuites among them (i.fft, i.segment, v.extract, v.surf.rst) pass against nc_spm.

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.

Cast the first operand so that integer products used as allocation
sizes, memset lengths, cell counts, and file offsets are computed in
size_t, long, or off_t instead of int, and so that int or float
products consumed as double (D_text_size, floor, region bounds) are
computed in double.

Fixes 24 CodeQL cpp/integer-multiplication-cast-to-long alerts across
display, general, imagery, raster3d, vector, and visualization tools.

@petrasovaa petrasovaa 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.

If you limit it to changes in d.graph/do_graph.c, d.legend/draw.c, r3.in.v5d, r3.out.v5d, i.segment/flag.c, v.vol.rst/user3.c, ximgview/color.c, I would approve it, the others have some issues that would require more thinking.

@cwhite911

Copy link
Copy Markdown
Contributor Author

If you limit it to changes in d.graph/do_graph.c, d.legend/draw.c, r3.in.v5d, r3.out.v5d, i.segment/flag.c, v.vol.rst/user3.c, ximgview/color.c, I would approve it, the others have some issues that would require more thinking.

Done

@cwhite911
cwhite911 requested a review from petrasovaa August 25, 2026 02:02
@cwhite911
cwhite911 enabled auto-merge (squash) August 25, 2026 02:28
@cwhite911
cwhite911 merged commit 9612019 into OSGeo:main Aug 25, 2026
26 checks passed
@github-actions github-actions Bot added this to the 8.6.0 milestone Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C Related code is in C display general imagery module raster3d vector Related to vector data processing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants