Skip to content

Potential fix for code scanning alert no. 7126: Multiplication result converted to larger type - #570

Draft
echoix wants to merge 5 commits into
mainfrom
alert-autofix-7126
Draft

echoix wants to merge 5 commits into
mainfrom
alert-autofix-7126

Conversation

@echoix

@echoix echoix commented Oct 20, 2025

Copy link
Copy Markdown
Owner

Potential fix for https://github.com/echoix/grass/security/code-scanning/7126

To address the risk of overflow, make sure the multiplication happens in double-precision, not a smaller data type. The most reliable fix is to cast either D_Cap->z or D_spec->yscale to double before performing the multiplication. This ensures the multiplication itself is evaluated in double-precision and no intermediate overflow can occur in smaller types. The required change is on line 69 in raster3d/r3.showdspf/draw_cappolys_ogl.c:
Change

tmpvt[t][1] = (D_Cap->z) * D_spec->yscale;

to

tmpvt[t][1] = ((double) D_Cap->z) * D_spec->yscale;

No imports or additional definitions are needed.


Suggested fixes powered by Copilot Autofix. Review carefully before merging.

echoix and others added 5 commits October 19, 2025 19:44
CI(CodeQL): Scan C/C++ with build-mode: none
… converted to larger type

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
for (t = start; t != stop; t += direction) {
tmpvt[t][0] = (vertices[t << 1] + xloc) * D_spec->xscale;
tmpvt[t][1] = (D_Cap->z) * D_spec->yscale;
tmpvt[t][1] = ((double) D_Cap->z) * D_spec->yscale;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[clang-format] reported by reviewdog 🐶

Suggested change
tmpvt[t][1] = ((double) D_Cap->z) * D_spec->yscale;
tmpvt[t][1] = ((double)D_Cap->z) * D_spec->yscale;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant