From 6b81420ce3562811fa2364e4d830968b145aea4d Mon Sep 17 00:00:00 2001 From: Norihiro Tanaka Date: Sat, 19 Apr 2014 10:48:49 +0900 Subject: [PATCH] grep: fix warnings around memory allocation in dfa.c * src/dfa.c (state_index): Fix it. (realloc_trans_if_necessary): Fix it. --- src/dfa.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/dfa.c b/src/dfa.c index eeca257..9a6aa5b 100644 --- a/src/dfa.c +++ b/src/dfa.c @@ -2084,7 +2084,7 @@ state_index (struct dfa *d, position_set const *s, int context) } /* We'll have to create a new state. */ - d->states = maybe_realloc (d->states, d->sindex, &d->salloc, + d->states = maybe_realloc (d->states, d->sindex, (size_t *) &d->salloc, sizeof *d->states); d->states[i].hash = hash; alloc_position_set (&d->states[i].elems, s->nelem); @@ -2780,12 +2780,11 @@ realloc_trans_if_necessary (struct dfa *d, state_num new_state) if (oldalloc <= new_state) { state_num **realtrans = d->trans ? d->trans - 1 : NULL; - size_t newalloc; - d->tralloc = new_state + 1; - realtrans = x2nrealloc (realtrans, &d->tralloc, sizeof *realtrans); + size_t newalloc = new_state + 1; + realtrans = x2nrealloc (realtrans, &newalloc, sizeof *realtrans); + d->tralloc = newalloc--; realtrans[0] = NULL; d->trans = realtrans + 1; - newalloc = --d->tralloc; d->fails = xnrealloc (d->fails, newalloc, sizeof *d->fails); d->success = xnrealloc (d->success, newalloc, sizeof *d->success); d->newlines = xnrealloc (d->newlines, newalloc, sizeof *d->newlines); -- 1.9.2