Repository navigation
Report an error instead of asserting when the token stream ends early (#386) - #397
Conversation
|
OK, I assume the assert was a stray debug assert during development. Can you please remove the comment from the PR, it refers to past history that would make no sense to a new reader, and the code is not special enough to warrant a comment here at all. Note that when injecting a null terminator, this is captured by the token case above the error, allowing the parser to produce a context specific error rather than unexpected end of file. |
…closes dvidelabs#386) next() advanced the token pointer and, on reaching the end of the token stream, hit assert(0) before the switch that handles exactly that case: if (P->token == P->te) { --P->token; assert(0); switch (P->token->id) { case LEX_TOK_EOS: case LEX_TOK_EOB: case LEX_TOK_EOF: P->token->id = LEX_TOK_EOF; return P->token; } error_tok(P, P->token, "unexpected end of input"); } The switch below the assert already produces a context-specific syntax error for an exhausted token stream, so the assert only turned those cases into an abort. It looks like a stray debug assert left in during development. A schema with an embedded NUL reaches this branch: schema.fbs: root_type\0DoubleVec; $ flatcc_d schema.fbs flatcc_d: parser.c:357: next: Assertion `0' failed. Aborted (core dumped) Removing it lets the existing handling run, and the same schema now fails with a normal error and exit status 255: schema.fbs:5:10: error: '': missing ';' expected by root_type
28f7693 to
fe8ecb2
Compare
|
Done — removed the comment, and the diff is now a one-line deletion: @@ -354,7 +354,6 @@ again:
if (P->token == P->te) {
/* We keep returning end of token to help binary operators etc., if any. */
--P->token;
- assert(0);
switch (P->token->id) {Thanks for pointing out that the null terminator is caught by the token case Re-checked after the edit: |
next()advanced the token pointer and, on reaching the end of the tokenstream, hit
assert(0)before theswitchthat was written to handleexactly that case (
src/compiler/parser.c:357):An embedded NUL in the schema truncates the token stream at the lexer level, so
a parser that has not yet consumed everything it expects reaches this branch and
aborts the whole compiler instead of reporting a syntax error.
Reproducer
57-byte schema (the
\0is a real NUL byte,0x00- not the two charactersx00):In a release build (
NDEBUG) the assert is compiled out and the compilerinstead walks into the switch below with the reduced token pointer, so the
debug build is what makes the bug visible.
Fix
Remove the
assert(0)so the handling directly below it runs. The same schemanow fails with a normal error and exit status 255:
Testing
SIGABRTbefore, clean error after.root_type<0x00>T;,table T {<0x00>},root_type T<0x00>;)all report errors rather than aborting.
.fbsfiles undertest/still compile.Fixes #386.