diff options
author | Akim Demaille <akim.demaille@gmail.com> | 2019-03-12 19:09:10 +0100 |
---|---|---|
committer | Akim Demaille <akim.demaille@gmail.com> | 2019-03-17 13:21:25 +0100 |
commit | 35add841ee3d5e499af0f9cfae227dc3ce62227d (patch) | |
tree | 3ce4c18bd378a70ee5e167bd2f7224d506f3f64d /src/state.c | |
parent | f6e38d7ac97aaeb77a97e3dc0af047c89a7e4402 (diff) | |
download | bison-35add841ee3d5e499af0f9cfae227dc3ce62227d.tar.gz |
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).
Diffstat (limited to 'src/state.c')
-rw-r--r-- | src/state.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/state.c b/src/state.c index b8b8e2ff..58980954 100644 --- a/src/state.c +++ b/src/state.c @@ -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; } |