]> granicus.if.org Git - re2c/commitdiff
Avoid calling 'memcpy' to copy zero bytes from NULL source.
authorUlya Trofimovich <skvadrik@gmail.com>
Mon, 31 Jul 2017 12:30:44 +0000 (13:30 +0100)
committerUlya Trofimovich <skvadrik@gmail.com>
Mon, 31 Jul 2017 12:58:19 +0000 (13:58 +0100)
With CXXFLAGS='-fsanitize=undefined' GCC complains about passing NULL
pointer to function which parameter is marked as 'attribute__((nonnull))'.

re2c/src/ast/scanner.cc
re2c/src/dfa/cfg/cfg.cc

index 7ed9f8744419af65dfaa7ab8779358747dc461fa..34e2b516dba31285882905a3380cd1264826492a 100644 (file)
@@ -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];
index e158365f285c1eb148d97d1a62e71d43eb360eaf..fc9c67403b14db4a88b75c45a47e480c79966126 100644 (file)
@@ -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<size_t>(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;
 }