summaryrefslogtreecommitdiff
path: root/src/symtab.c
diff options
context:
space:
mode:
authorAkim Demaille <akim.demaille@gmail.com>2020-03-08 07:27:57 +0100
committerAkim Demaille <akim.demaille@gmail.com>2020-03-08 08:10:11 +0100
commitcfcd823e160121d8be7463b8b47600ff50c3cbd3 (patch)
tree420fc6f871baf0f2a0f04c2a8a0f0ef0433ce12d /src/symtab.c
parent2f02d9beae83156c60fa4ba7da05d78cd01e88da (diff)
downloadbison-cfcd823e160121d8be7463b8b47600ff50c3cbd3.tar.gz
diagnostics: don't crash because of repeated definitions of error
According to https://www.unix.com/man-page/POSIX/1posix/yacc/, the user is allowed to specify her user number for the error token: The token error shall be reserved for error handling. The name error can be used in grammar rules. It indicates places where the parser can recover from a syntax error. The default value of error shall be 256. Its value can be changed using a %token declaration. The lexical analyzer should not return the value of error. I think this feature is useless, the user should not have to deal with that. The intend is probably to give the user a means to use 256 if she wants to, but provided "error" cleared the path first by being assigned another number. In the case of Bison, 256 is assigned to "error" at the end if the user did not use it for a token of hers. So this feature is useless. Yet it is valid, and if the user assigns twice a token number to "error", then the second time we want to complain about it and want to show the original definition. At this point, we try to display the built-in definition of "error", whose location is NULL, and we crash. Rather, the location of the first user definition of "error" should become its defining location. Reported byg Ahcheong Lee. https://lists.gnu.org/r/bug-bison/2020-03/msg00007.html * src/symtab.c (symbol_class_set): If this is a declaration and the symbol was not declared yet, keep this as defining location. * tests/input.at (Redefining the error token): New.
Diffstat (limited to 'src/symtab.c')
-rw-r--r--src/symtab.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/symtab.c b/src/symtab.c
index b137bbf0..b4106ea0 100644
--- a/src/symtab.c
+++ b/src/symtab.c
@@ -555,7 +555,10 @@ symbol_class_set (symbol *sym, symbol_class class, location loc, bool declaring)
_("previous declaration"));
}
else
- s->status = declared;
+ {
+ sym->location = loc;
+ s->status = declared;
+ }
}
}
}