mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-12 13:53:03 +00:00
address warnings from GCC's UB sanitizer
Running with CC='gcc-mp-8 -fsanitize=undefined' revealed Undefined Behaviors. https://lists.gnu.org/archive/html/bison-patches/2019-03/msg00008.html * src/state.c (errs_new): Don't call memcpy with NULL as source. * src/location.c (add_column_width): Don't assume that the column argument is nonnegative: the scanner sometimes "backtracks" (e.g., see ROLLBACK_CURRENT_TOKEN and DEPRECATED) in which case we can have negative column numbers (temporarily). Found in test 3 (Invalid inputs).
This commit is contained in:
@@ -77,7 +77,8 @@ errs_new (int num, symbol **tokens)
|
||||
size_t symbols_size = num * sizeof *tokens;
|
||||
errs *res = xmalloc (offsetof (errs, symbols) + symbols_size);
|
||||
res->num = num;
|
||||
memcpy (res->symbols, tokens, symbols_size);
|
||||
if (tokens)
|
||||
memcpy (res->symbols, tokens, symbols_size);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user