public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* ubsan: logical_input_line signed integer overflow
@ 2022-03-18  6:51 Alan Modra
  0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2022-03-18  6:51 UTC (permalink / raw)
  To: binutils

To avoid a completely useless fuzzing ubsan "bug" report, I decided to
make logical_input_line unsigned.

	* input-scrub.c (logical_input_line): Make unsigned.
	(struct input_save): Here too.
	(input_scrub_reinit, input_scrub_close, bump_line_counters),
	(as_where): Adjust to suit.

diff --git a/gas/input-scrub.c b/gas/input-scrub.c
index 37877bffe1c..26af4fec5db 100644
--- a/gas/input-scrub.c
+++ b/gas/input-scrub.c
@@ -102,7 +102,7 @@ static const char *logical_input_file;
 /* 1-origin line number in a source file.  */
 /* A line ends in '\n' or eof.  */
 static unsigned int physical_input_line;
-static int logical_input_line;
+static unsigned int logical_input_line;
 
 /* Struct used to save the state of the input handler during include files */
 struct input_save {
@@ -111,10 +111,10 @@ struct input_save {
   size_t              partial_size;
   char                save_source[AFTER_SIZE];
   size_t              buffer_length;
-  const char *              physical_input_file;
-  const char *              logical_input_file;
+  const char *        physical_input_file;
+  const char *        logical_input_file;
   unsigned int        physical_input_line;
-  int                 logical_input_line;
+  unsigned int        logical_input_line;
   size_t              sb_index;
   sb                  from_sb;
   int                 from_sb_is_expansion; /* Should we do a conditional check?  */
@@ -137,7 +137,7 @@ static void
 input_scrub_reinit (void)
 {
   input_file_begin ();		/* Reinitialize! */
-  logical_input_line = -1;
+  logical_input_line = -1u;
   logical_input_file = NULL;
 
   buffer_length = input_file_buffer_size () * 2;
@@ -304,7 +304,7 @@ input_scrub_close (void)
 {
   input_file_close ();
   physical_input_line = 0;
-  logical_input_line = -1;
+  logical_input_line = -1u;
 }
 
 char *
@@ -431,7 +431,7 @@ bump_line_counters (void)
   if (sb_index == (size_t) -1)
     {
       ++physical_input_line;
-      if (logical_input_line >= 0)
+      if (logical_input_line != -1u)
 	++logical_input_line;
     }
 }
@@ -515,7 +515,7 @@ const char *
 as_where (unsigned int *linep)
 {
   if (logical_input_file != NULL
-      && (linep == NULL || logical_input_line >= 0))
+      && (linep == NULL || logical_input_line != -1u))
     {
       if (linep != NULL)
 	*linep = logical_input_line;

-- 
Alan Modra
Australia Development Lab, IBM

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

only message in thread, other threads:[~2022-03-18  6:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-18  6:51 ubsan: logical_input_line signed 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).