Skip to content

lib/ogsf, lib/nviz: Fix multiplications converted to a larger type - #7704

Merged
cwhite911 merged 1 commit into
OSGeo:mainfrom
cwhite911:ogsf-int-mult
Jul 14, 2026
Merged

cwhite911 merged 1 commit into
OSGeo:mainfrom
cwhite911:ogsf-int-mult

Conversation

@cwhite911

Copy link
Copy Markdown
Contributor

Fixes the 33 CodeQL cpp/integer-multiplication-cast-to-long alerts in lib/ogsf and lib/nviz.

Three patterns, following the idiom from ed986f8 (cast the first operand so the product is computed in the destination type):

  • Row/column offset arithmetic assigned to long (y1off = row * ymod * surf->cols and friends in gsd_surf.c, gsd_wire.c, gsd_fringe.c, gs_norms.c, and the norms buffer size in gs.c): the product was computed in int and could overflow for very large rasters before being widened. Now computed in long.
  • float products assigned to double (lights.c, gsd_cplane.c): computed in double via a cast on the first operand.
  • gsd_views.c gsd_surf2model(): the multiplication result was widened to double only because the ternary's other branch was the double literal 0.0, then narrowed back into a float Point3. Made the literals 0.0f instead, which keeps the arithmetic in float and removes the pointless round trip.

Verification: both libraries compile cleanly, and m.nviz.image renders (fine-mode surface exercising gsd_surf.c, and wireframe exercising gsd_wire.c) are bit-identical before and after the change.

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 offset computations like
row * ymod * cols are done in long, not int, matching the long
variables they are assigned to, and so that float products assigned
to double variables are computed in double. In gsd_surf2model, make
the ternary literals float to avoid a pointless float-double-float
round trip for values stored back into a float Point3.

Fixes 33 CodeQL cpp/integer-multiplication-cast-to-long alerts.
@github-actions github-actions Bot added C Related code is in C libraries labels Jul 14, 2026
@cwhite911
cwhite911 enabled auto-merge (squash) July 14, 2026 17:54
@cwhite911
cwhite911 merged commit 7d24287 into OSGeo:main Jul 14, 2026
25 of 26 checks passed
@github-actions github-actions Bot added this to the 8.6.0 milestone Jul 14, 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 libraries

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants