From 7a7a860f98c56bdc0ab4d0ee033e7b1947241806 Mon Sep 17 00:00:00 2001 From: Mohan Yelugoti Date: Fri, 1 Nov 2024 19:18:43 -0400 Subject: [PATCH] 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 --- lib/ogsf/gvld.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ogsf/gvld.c b/lib/ogsf/gvld.c index 91734eaac49..9c0831b5bcd 100644 --- a/lib/ogsf/gvld.c +++ b/lib/ogsf/gvld.c @@ -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;