lalr: don't overbook memory

I never understood why we book ngotos+1 slots for relations between
gotos: there are at most ngotos images, not ngotos+1 (and "includes"
does have cases where a goto is in relation with itself, so it's not
ngotos-1).

Maybe bbf37f2534 explains the +1: a bug
left us register a goto several times on occasion, and the +1 might
have been a means to avoid this problem in most cases.  Now that this
bug is addressed, we should no longer overbook memory, if only for the
clarity of the code ("why ngotos+1 instead of ngotos?").

* src/lalr.c: A goto has at most ngotos images, not ngotos+1.
While at it, avoid useless repeated call to map_goto introduced in
bbf37f2534.
This commit is contained in:
Akim Demaille
2019-03-31 09:23:39 +02:00
parent 6d4e6bf118
commit 18831f985c

View File

@@ -192,7 +192,7 @@ static void
initialize_goto_follows (void)
{
goto_number **reads = xnmalloc (ngotos, sizeof *reads);
goto_number *edge = xnmalloc (ngotos + 1, sizeof *edge);
goto_number *edge = xnmalloc (ngotos, sizeof *edge);
goto_number nedges = 0;
goto_follows = bitsetv_create (ngotos, ntokens, BITSET_FIXED);
@@ -211,7 +211,7 @@ initialize_goto_follows (void)
symbol_number sym = TRANSITION_SYMBOL (trans, j);
if (nullable[sym - ntokens])
{
assert (nedges < ngotos + 1);
assert (nedges < ngotos);
edge[nedges++] = map_goto (dst, sym);
}
}
@@ -309,7 +309,7 @@ add_lookback_edge (state *s, rule const *r, goto_number gotono)
static void
build_relations (void)
{
goto_number *edge = xnmalloc (ngotos + 1, sizeof *edge);
goto_number *edge = xnmalloc (ngotos, sizeof *edge);
state_number *path = xnmalloc (ritem_longest_rhs () + 1, sizeof *path);
includes = xnmalloc (ngotos, sizeof *includes);
@@ -361,8 +361,8 @@ build_relations (void)
found = edge[j] == g;
if (!found)
{
assert (nedges < ngotos + 1);
edge[nedges++] = map_goto (path[p], sym);
assert (nedges < ngotos);
edge[nedges++] = g;
}
}
if (!nullable[sym - ntokens])