]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
gmon: Fix UB in tst-sprofil.c
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Fri, 25 Apr 2025 18:26:35 +0000 (15:26 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 8 May 2025 12:25:49 +0000 (09:25 -0300)
UBSAN: Undefined behaviour in tst-sprofil.c:140:6 unsigned integer overflow: 2432902008176640000 + 7812407968270641256 cannot be represened in type 'long int'

Use unsigned types for the fibonacci.

gmon/tst-sprofil.c

index 55cf99abf48e51826d2097820fc1591f26e29045..15d71762c8edc3d23d4d1fec53e32554c1bbe356 100644 (file)
@@ -45,8 +45,8 @@ unsigned int bshort[5][0x100 / sizeof (int)];
 unsigned int blong[1][0x1000 / sizeof (int)];
 unsigned int vlong[1][0x2000 / sizeof (int)];
 
-static long int
-fac (long int n)
+static long unsigned int
+fac (long int unsigned n)
 {
   if (n == 0)
     return 1;
@@ -60,7 +60,7 @@ main (int argc, char **argv)
   struct timeval tv, start;
   struct prof prof[32];
   double t_tick, delta;
-  long int sum = 0;
+  long int unsigned sum = 0;
   int i, j;
 
   for (i = 0; i < NELEMS (taddr); ++i)