Produce better error message on malformed while loop

echo "void bugged() { do {} }" | tcc -run -
now produces the sensible:  -:1: error: 'while' expected (got "}")

I believe (but am far from sure) that the additional use of &tokc is ok.
This commit is contained in:
Eric Raible 2023-10-03 22:11:59 -07:00
parent 3d128041c3
commit b214fb6ed3

View file

@ -98,8 +98,11 @@ static void next_nomacro(void);
ST_FUNC void skip(int c)
{
if (tok != c)
tcc_error("'%c' expected (got \"%s\")", c, get_tok_str(tok, &tokc));
if (tok != c) {
char tmp[40];
pstrcpy(tmp, sizeof tmp, get_tok_str(c, &tokc));
tcc_error("'%s' expected (got \"%s\")", tmp, get_tok_str(tok, &tokc));
}
next();
}