Avoid undefined behavior that accessed just before the start of an array.

* src/reader.c (packgram): Prepend a new sentinel before ritem.
* src/lalr.c (build_relations): Rely on new sentinel.
* src/gram.c (gram_free): Adjust to new sentinel.
This commit is contained in:
Paul Eggert
2006-01-18 23:48:29 +00:00
parent 02d7cce6e2
commit e9ad4aeca5
4 changed files with 24 additions and 9 deletions

View File

@@ -418,7 +418,11 @@ packgram (void)
rule_number ruleno = 0;
symbol_list *p = grammar;
ritem = xnmalloc (nritems, sizeof *ritem);
ritem = xnmalloc (nritems + 1, sizeof *ritem);
/* This sentinel is used by build_relations in gram.c. */
*ritem++ = 0;
rules = xnmalloc (nrules, sizeof *rules);
while (p)