Skip to content

Commit

Permalink
Fix compiler crash on constant arrays in conditions
Browse files Browse the repository at this point in the history
Code like:

if ("") // blabla
or
if ({1,2}) // bla

causes an "array must be indexed" error and crashes when it tries to
print the variable name of the array - because there is none for a
constant inline array.

This patch throws an "invalid expression" error instead.
  • Loading branch information
peace-maker committed Jul 11, 2016
1 parent 594bfbb commit 8153433
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions compiler/sc1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5926,8 +5926,10 @@ static int test(int label,int parens,int invert)
if (endtok!=0)
needtoken(endtok);
if (ident==iARRAY || ident==iREFARRAY) {
const char *ptr=sym->name;
error(33,ptr); /* array must be indexed */
if (sym)
error(33, (const char *)sym->name); /* array must be indexed */
else
error(29); /* invalid expression */
} /* if */
if (ident==iCONSTEXPR) { /* constant expression */
int testtype=0;
Expand Down

0 comments on commit 8153433

Please sign in to comment.