Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash from an incomplete do-while statement #680

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions source/compiler/sc1.c
Original file line number Diff line number Diff line change
Expand Up @@ -5972,6 +5972,7 @@ static int test(int label,int parens,int invert)
cell cidx;
int ident,tag;
int endtok;
short save_intest;
cell constval;
symbol *sym;
int localstaging=FALSE;
Expand All @@ -5985,7 +5986,7 @@ static int test(int label,int parens,int invert)
#endif
} /* if */

PUSHSTK_I(sc_intest);
save_intest=sc_intest;
sc_intest=TRUE;
endtok=0;
if (parens!=TEST_PLAIN) {
Expand Down Expand Up @@ -6016,7 +6017,7 @@ static int test(int label,int parens,int invert)
} /* if */
if (ident==iCONSTEXPR) { /* constant expression */
int testtype=0;
sc_intest=(short)POPSTK_I();/* restore stack */
sc_intest=save_intest; /* restore stack */
stgdel(index,cidx);
if (constval) { /* code always executed */
error(206); /* redundant test: always non-zero */
Expand All @@ -6039,7 +6040,7 @@ static int test(int label,int parens,int invert)
else
jmp_eq0(label); /* jump to label if false (equal to 0) */
markexpr(sEXPR,NULL,0); /* end expression (give optimizer a chance) */
sc_intest=(short)POPSTK_I(); /* double typecast to avoid warning with Microsoft C */
sc_intest=save_intest;
if (localstaging) {
stgout(0); /* output queue from the very beginning (see
* assert() when localstaging is set to TRUE) */
Expand Down
7 changes: 7 additions & 0 deletions source/compiler/tests/incomplete_dowhile_crash.meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
'test_type': 'output_check',
'errors': """
incomplete_dowhile_crash.pwn(6) : error 001: expected token: "while", but found "}"
incomplete_dowhile_crash.pwn(7) : error 001: expected token: ";", but found "-end of file-"
"""
}
6 changes: 6 additions & 0 deletions source/compiler/tests/incomplete_dowhile_crash.pwn
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma option -;+

main()
{
do {}
}