From 3e0c5ba9c0ae9ff3c86269010237c356d6bbd1fc Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Wed, 29 Sep 2021 20:48:46 +0700 Subject: [PATCH 1/3] Fix crash from incomplete `do-while` statement --- source/compiler/sc1.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index a50409ea..e08accaf 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -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; @@ -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) { @@ -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) */ From f053b83a48f81287c2871a5b00445fb102b73f86 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Wed, 29 Sep 2021 22:57:33 +0700 Subject: [PATCH 2/3] Add a test --- source/compiler/tests/incomplete_dowhile_crash.meta | 7 +++++++ source/compiler/tests/incomplete_dowhile_crash.pwn | 6 ++++++ 2 files changed, 13 insertions(+) create mode 100644 source/compiler/tests/incomplete_dowhile_crash.meta create mode 100644 source/compiler/tests/incomplete_dowhile_crash.pwn diff --git a/source/compiler/tests/incomplete_dowhile_crash.meta b/source/compiler/tests/incomplete_dowhile_crash.meta new file mode 100644 index 00000000..8a71c3f2 --- /dev/null +++ b/source/compiler/tests/incomplete_dowhile_crash.meta @@ -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-" +""" +} diff --git a/source/compiler/tests/incomplete_dowhile_crash.pwn b/source/compiler/tests/incomplete_dowhile_crash.pwn new file mode 100644 index 00000000..ef74bd89 --- /dev/null +++ b/source/compiler/tests/incomplete_dowhile_crash.pwn @@ -0,0 +1,6 @@ +#pragma option -;+ + +main() +{ + do {} +} From 1e43ec04b5d5c4cd7a99907d68031e0a63ec8b83 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Tue, 8 Mar 2022 21:39:14 +0700 Subject: [PATCH 3/3] Forgot to replace one use of POPSTK_I --- source/compiler/sc1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index e08accaf..cb9bce2b 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -6017,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 */