From 646598785915b6599596e8456567bfb5aff36a26 Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella Date: Fri, 25 Apr 2025 15:26:35 -0300 Subject: [PATCH] gmon: Fix UB in tst-sprofil.c 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 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gmon/tst-sprofil.c b/gmon/tst-sprofil.c index 55cf99abf4..15d71762c8 100644 --- a/gmon/tst-sprofil.c +++ b/gmon/tst-sprofil.c @@ -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) -- 2.47.2