Skip to content

Commit

Permalink
ogsf: fix possible overflow errors in gvld module
Browse files Browse the repository at this point in the history
We were doing `(255 << 24)` which causes integer overflow
and positive number gets converted to negative number. We
were then assigning this to an unsigned integer in multiple
places, which does conversion in a different way.

For example: If we do unsigned int x = -20, `UINT_MAX + 1 - 20`
is assigned to x.

I do not think that's what is intended when we do
`ktrans = (255 << 24)`. Fix instances of that, by using an
unsigned int literal over int literal.

This issue was found using cppcheck tool.

Signed-off-by: Mohan Yelugoti <[email protected]>
  • Loading branch information
ymdatta committed Nov 1, 2024
1 parent cb3d12b commit 7a7a860
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ogsf/gvld.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ int gvld_isosurf(geovol *gvl)

/* transparency */
check_transp[i] = 0;
ktrans[i] = (255 << 24);
ktrans[i] = (255U << 24);
if (CONST_ATT == isosurf->att[ATT_TRANSP].att_src &&
isosurf->att[ATT_TRANSP].constant != 0.0) {
ktrans[i] = (255 - (int)isosurf->att[ATT_TRANSP].constant) << 24;
Expand Down

0 comments on commit 7a7a860

Please sign in to comment.