summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNorihiro Tanaka <noritnk@kcn.ne.jp>2014-11-15 22:21:34 -0800
committerJim Meyering <meyering@fb.com>2014-11-16 07:45:35 -0800
commita07a473b558709741ef9a39a97a65ddcedc41eb3 (patch)
tree20d5a69cd9f97d9d57f7007350503676c019875a
parent37d90d5ae4c4a42f59fa655529483827f687d91c (diff)
downloadgrep-a07a473b558709741ef9a39a97a65ddcedc41eb3.tar.gz
dfa: avoid undefined behavior
* src/dfa.c (dfassbuild): Don't call memcpy with a second argument of NULL, even when the size (3rd argument) is 0.
-rw-r--r--src/dfa.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/dfa.c b/src/dfa.c
index e0fc120c..65862e8b 100644
--- a/src/dfa.c
+++ b/src/dfa.c
@@ -3660,8 +3660,11 @@ dfassbuild (struct dfa *d)
sup->musts = NULL;
sup->charclasses = xnmalloc (sup->calloc, sizeof *sup->charclasses);
- memcpy (sup->charclasses, d->charclasses,
- d->cindex * sizeof *sup->charclasses);
+ if (d->cindex)
+ {
+ memcpy (sup->charclasses, d->charclasses,
+ d->cindex * sizeof *sup->charclasses);
+ }
sup->tokens = xnmalloc (d->tindex, 2 * sizeof *sup->tokens);
sup->talloc = d->tindex * 2;