Skip to content

Commit

Permalink
lib/ogsf: fix possible overflow errors in gvld.c (#4637)
Browse files Browse the repository at this point in the history
ogsf: fix possible overflow errors in gvld module

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 authored Nov 5, 2024
1 parent 4854f49 commit c1d8557
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 c1d8557

Please sign in to comment.