>From 5332a21b1188224ecddbbe8b234b618d0b84437a Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 13 Sep 2020 18:27:07 -0700 Subject: [PATCH 6/7] dfa: assume C99 in reorder_tokens * lib/dfa.c (reorder_tokens): Assume C99 and simplify. --- ChangeLog | 3 +++ lib/dfa.c | 32 ++++++++++---------------------- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1b5720761..5f7a148e3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2020-09-13 Paul Eggert + dfa: assume C99 in reorder_tokens + * lib/dfa.c (reorder_tokens): Assume C99 and simplify. + dfa: fix dfa-heap-overrun failure * lib/dfa.c (reorder_tokens): When setting map[d->follows[i].elems[j].index], instead of incorrectly assuming diff --git a/lib/dfa.c b/lib/dfa.c index 4992bcaf2..0fa9958fd 100644 --- a/lib/dfa.c +++ b/lib/dfa.c @@ -2494,39 +2494,27 @@ compare (const void *a, const void *b) static void reorder_tokens (struct dfa *d) { - idx_t nleaves; - ptrdiff_t *map; - token *tokens; - position_set *follows; - int *constraints; - char *multibyte_prop; - - nleaves = 0; - - map = xnmalloc (d->tindex, sizeof *map); - + idx_t nleaves = 0; + ptrdiff_t *map = xnmalloc (d->tindex, sizeof *map); map[0] = nleaves++; - for (idx_t i = 1; i < d->tindex; i++) map[i] = -1; - tokens = xnmalloc (d->nleaves, sizeof *tokens); - follows = xnmalloc (d->nleaves, sizeof *follows); - constraints = xnmalloc (d->nleaves, sizeof *constraints); - - if (d->localeinfo.multibyte) - multibyte_prop = xnmalloc (d->nleaves, sizeof *multibyte_prop); - else - multibyte_prop = NULL; + token *tokens = xnmalloc (d->nleaves, sizeof *tokens); + position_set *follows = xnmalloc (d->nleaves, sizeof *follows); + int *constraints = xnmalloc (d->nleaves, sizeof *constraints); + char *multibyte_prop = (d->localeinfo.multibyte + ? xnmalloc (d->nleaves, sizeof *multibyte_prop) + : NULL); for (idx_t i = 0; i < d->tindex; i++) for (idx_t j = 0; j < d->follows[i].nelem; j++) - if (map[d->follows[i].elems[j].index] == -1) + if (map[d->follows[i].elems[j].index] < 0) map[d->follows[i].elems[j].index] = nleaves++; for (idx_t i = 0; i < d->tindex; i++) { - if (map[i] == -1) + if (map[i] < 0) { free (d->follows[i].elems); d->follows[i].elems = NULL; -- 2.17.1