From: Alan Modra Date: Fri, 18 Mar 2022 02:46:43 +0000 (+1030) Subject: ubsan: logical_input_line signed integer overflow X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ecc263d676f1b9b568d95d9b6f678186cc825670;p=binutils-gdb.git ubsan: logical_input_line signed integer overflow 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;