From: Adhemerval Zanella Date: Fri, 18 Apr 2025 13:03:56 +0000 (-0300) Subject: stdio: Fix UB on snprintf X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5197a3a2f7118266b139653a45bd1e9900529091;p=thirdparty%2Fglibc.git stdio: Fix UB on snprintf The elf/tst-dl-printf-static test when built with ubsan triggers: UBSAN: Undefined behaviour in vfprintf-process-arg.c:58:36 negation of 9223372036854775808 cannot be represented in type 'long int' --- diff --git a/stdio-common/vfprintf-process-arg.c b/stdio-common/vfprintf-process-arg.c index 90b5e61ceb..a41feb2c47 100644 --- a/stdio-common/vfprintf-process-arg.c +++ b/stdio-common/vfprintf-process-arg.c @@ -55,7 +55,8 @@ LABEL (form_integer): signed_number = (short int) process_arg_unsigned_int (); is_negative = signed_number < 0; - number.word = is_negative ? (- signed_number) : signed_number; + number.word = is_negative ? (- (unsigned long) signed_number) + : signed_number; goto LABEL (number); }