From d0dfcc2bb9de55a97a91115bce155bd730fc6e16 Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Mon, 31 Jul 2017 13:30:44 +0100 Subject: [PATCH] Avoid calling 'memcpy' to copy zero bytes from NULL source. With CXXFLAGS='-fsanitize=undefined' GCC complains about passing NULL pointer to function which parameter is marked as 'attribute__((nonnull))'. --- re2c/src/ast/scanner.cc | 4 +++- re2c/src/dfa/cfg/cfg.cc | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/re2c/src/ast/scanner.cc b/re2c/src/ast/scanner.cc index 7ed9f874..34e2b516 100644 --- a/re2c/src/ast/scanner.cc +++ b/re2c/src/ast/scanner.cc @@ -68,7 +68,9 @@ void Scanner::fill (uint32_t need) { fatal("Out of memory"); } - memcpy (buf, bot, copy); + if (copy > 0) { + memcpy (buf, bot, copy); + } tok = &buf[tok - bot]; mar = &buf[mar - bot]; ptr = &buf[ptr - bot]; diff --git a/re2c/src/dfa/cfg/cfg.cc b/re2c/src/dfa/cfg/cfg.cc index e158365f..fc9c6740 100644 --- a/re2c/src/dfa/cfg/cfg.cc +++ b/re2c/src/dfa/cfg/cfg.cc @@ -125,7 +125,7 @@ cfg_bb_t::cfg_bb_t(const cfg_ix_t *sb, const cfg_ix_t *se, { const size_t n = static_cast(se - sb); succb = new cfg_ix_t[n]; - memcpy(succb, sb, n * sizeof(cfg_ix_t)); + if (n > 0) memcpy(succb, sb, n * sizeof(cfg_ix_t)); succe = succb + n; } -- 2.40.0