Repository navigation
lib/ogsf, lib/nviz: Fix multiplications converted to a larger type - #7704
Merged
Merged
Conversation
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.
petrasovaa
approved these changes
Jul 14, 2026
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 the 33 CodeQL
cpp/integer-multiplication-cast-to-longalerts 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):
long(y1off = row * ymod * surf->colsand friends ingsd_surf.c,gsd_wire.c,gsd_fringe.c,gs_norms.c, and thenormsbuffer size ings.c): the product was computed inintand could overflow for very large rasters before being widened. Now computed inlong.floatproducts assigned todouble(lights.c,gsd_cplane.c): computed indoublevia a cast on the first operand.gsd_views.cgsd_surf2model(): the multiplication result was widened todoubleonly because the ternary's other branch was the double literal0.0, then narrowed back into a floatPoint3. Made the literals0.0finstead, which keeps the arithmetic in float and removes the pointless round trip.Verification: both libraries compile cleanly, and
m.nviz.imagerenders (fine-mode surface exercisinggsd_surf.c, and wireframe exercisinggsd_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.