public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: binutils@sourceware.org
Subject: ubsan: s_app_line integer overflow
Date: Wed, 16 Feb 2022 22:04:02 +1030	[thread overview]
Message-ID: <YgzhKqo/Vjof9Wzt@squeak.grove.modra.org> (raw)

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

                 reply	other threads:[~2022-02-16 11:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YgzhKqo/Vjof9Wzt@squeak.grove.modra.org \
    --to=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).