[binutils-gdb] libiberty d_compact_number signed integer overflow

Alan Modra via Gdb-cvs <[email protected]> Wed, 1 Jul 2026 01:44:59 +0000 (GMT)
Newsgroups gmane.comp.gdb.cvs
Message-ID <20260701014459.F2FF44BA23C9__28118.2805121475$1782870308$gmane$org@sourceware.org>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=54e80f9747d62efea50038655801ecb58d37b507

commit 54e80f9747d62efea50038655801ecb58d37b507
Author: Alan Modra <[email protected]>
Date:   Wed Jul 1 10:57:51 2026 +0930

    libiberty d_compact_number signed integer overflow
    
    https://lists.gnu.org/archive/html/bug-binutils/2026-06/msg00189.html
    Fix this by doing the addition in unsigned arithmetic.

Diff:
---
 libiberty/cp-demangle.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c
index 5f08ef8946a..ab122fc388d 100644
--- a/libiberty/cp-demangle.c
+++ b/libiberty/cp-demangle.c
@@ -3266,7 +3266,7 @@ d_compact_number (struct d_info *di)
   else if (d_peek_char (di) == 'n')
     return -1;
   else
-    num = d_number (di) + 1;
+    num = d_number (di) + 1u;
 
   if (num < 0 || ! d_check_char (di, '_'))
     return -1;