Avoid possible signed overflow in decode_local_label_name

Message ID ZoTr384PdyZixKbe@squeak.grove.modra.org
State New
Headers
Series Avoid possible signed overflow in decode_local_label_name |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm warning Patch is already merged
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 warning Patch is already merged

Commit Message

Alan Modra July 3, 2024, 6:12 a.m. UTC
  This avoids signed overflow in the "10 * x + *p - '0'" expressions.
Matches what both fb_label_name and dollar_label_name use.

	* symbols.c (decode_local_label_name): Use unsigned variables.
  

Patch

diff --git a/gas/symbols.c b/gas/symbols.c
index b57dbfc64f4..fa3aaa37ed4 100644
--- a/gas/symbols.c
+++ b/gas/symbols.c
@@ -2185,11 +2185,11 @@  decode_local_label_name (char *s)
 {
   char *p;
   char *symbol_decode;
-  int label_number;
-  int instance_number;
+  unsigned int label_number;
+  unsigned int instance_number;
   const char *type;
   const char *message_format;
-  int lindex = 0;
+  unsigned int lindex = 0;
 
 #ifdef LOCAL_LABEL_PREFIX
   if (s[lindex] == LOCAL_LABEL_PREFIX)
@@ -2212,7 +2212,7 @@  decode_local_label_name (char *s)
   for (instance_number = 0, p++; ISDIGIT (*p); ++p)
     instance_number = (10 * instance_number) + *p - '0';
 
-  message_format = _("\"%d\" (instance number %d of a %s label)");
+  message_format = _("\"%u\" (instance number %u of a %s label)");
   symbol_decode = notes_alloc (strlen (message_format) + 30);
   sprintf (symbol_decode, message_format, label_number, instance_number, type);