diff --git a/tools/lemon/lemon.c b/tools/lemon/lemon.c index 5801591db0..102a86c270 100644 --- a/tools/lemon/lemon.c +++ b/tools/lemon/lemon.c @@ -495,6 +495,7 @@ void acttab_action(acttab *p, int lookahead, int action){ */ int acttab_insert(acttab *p){ int i, j, k, n; + int nActtab; /* Number of slots in the p->aAction[] table */ assert( p->nLookahead>0 ); /* Make sure we have enough space to hold the expanded action table @@ -502,7 +503,8 @@ int acttab_insert(acttab *p){ ** must be appended to the current action table */ n = p->mxLookahead + 1; - if( p->nAction + n >= p->nActionAlloc ){ + nActtab = p->nAction + n; + if( nActtab >= p->nActionAlloc ){ int oldAlloc = p->nActionAlloc; p->nActionAlloc = p->nAction + n + p->nActionAlloc + 20; p->aAction = realloc( p->aAction, @@ -520,11 +522,11 @@ int acttab_insert(acttab *p){ /* Scan the existing action table looking for an offset where we can ** insert the current transaction set. Fall out of the loop when that ** offset is found. In the worst case, we fall out of the loop when - ** i reaches p->nAction, which means we append the new transaction set. + ** i reaches nActtab, which means we append the new transaction set. ** ** i is the index in p->aAction[] where p->mnLookahead is inserted. */ - for(i=p->nAction-1; i>=0; i--){ + for(i=nActtab-1; i>=0; i--){ /* First look for an existing action table entry that can be reused */ if( p->aAction[i].lookahead==p->mnLookahead ){ if( p->aAction[i].action!=p->mnAction ) continue; @@ -547,7 +549,7 @@ int acttab_insert(acttab *p){ } if( i<0 ){ /* If no reusable entry is found, look for an empty slot */ - for(i=0; inAction; i++){ + for(i=0; iaAction[i].lookahead<0 ){ for(j=0; jnLookahead; j++){ k = p->aLookahead[j].lookahead - p->mnLookahead + i;