From fe8ecb298f35fad43fc323af89f1232a1aee4c87 Mon Sep 17 00:00:00 2001 From: 1820893135-pixel <1820893135@qq.com> Date: Wed, 23 Sep 2026 17:45:14 +0800 Subject: [PATCH] Report an error instead of asserting when the token stream ends early (closes #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 --- src/compiler/parser.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/compiler/parser.c b/src/compiler/parser.c index b179be567..45b5c9da2 100644 --- a/src/compiler/parser.c +++ b/src/compiler/parser.c @@ -354,7 +354,6 @@ static fb_token_t *next(fb_parser_t *P) 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) { case LEX_TOK_EOS: case LEX_TOK_EOB: case LEX_TOK_EOF: P->token->id = LEX_TOK_EOF;