public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* ubsan: s_app_line integer overflow
@ 2022-02-16 11:34 Alan Modra
  0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2022-02-16 11:34 UTC (permalink / raw)
  To: binutils

There are quite a few ubsan warnings in gas.  This one disappears with
a code tidy.

	* read.c (s_app_line): Rename 'l' to 'linenum'.  Avoid ubsan
	warning.

diff --git a/gas/read.c b/gas/read.c
index 523708faa97..f3635626649 100644
--- a/gas/read.c
+++ b/gas/read.c
@@ -2068,20 +2068,18 @@ void
 s_app_line (int appline)
 {
   char *file = NULL;
-  int l;
+  int linenum;
 
   /* The given number is that of the next line.  */
   if (appline)
-    l = get_absolute_expression ();
-  else if (!get_linefile_number (&l))
+    linenum = get_absolute_expression ();
+  else if (!get_linefile_number (&linenum))
     {
       ignore_rest_of_line ();
       return;
     }
 
-  l--;
-
-  if (l < -1)
+  if (linenum < 0)
     /* Some of the back ends can't deal with non-positive line numbers.
        Besides, it's silly.  GCC however will generate a line number of
        zero when it is pre-processing builtins for assembler-with-cpp files:
@@ -2092,7 +2090,7 @@ s_app_line (int appline)
        in the GCC and GDB testsuites.  So we check for negative line numbers
        rather than non-positive line numbers.  */
     as_warn (_("line numbers must be positive; line number %d rejected"),
-	     l + 1);
+	     linenum);
   else
     {
       int flags = 0;
@@ -2152,10 +2150,11 @@ s_app_line (int appline)
 
       if (appline || file)
 	{
-	  new_logical_line_flags (file, l, flags);
+	  linenum--;
+	  new_logical_line_flags (file, linenum, flags);
 #ifdef LISTING
 	  if (listing)
-	    listing_source_line (l);
+	    listing_source_line (linenum);
 #endif
 	}
     }

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-02-16 11:34 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-16 11:34 ubsan: s_app_line integer overflow Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).