From 5c4c6aee716827fc7d10e91e3ec96d0afcedbc6f Mon Sep 17 00:00:00 2001 From: Jeremiah Orians Date: Thu, 30 Jan 2020 18:40:45 -0500 Subject: [PATCH] prevent void foo () { if(0) {} class of segfaults --- cc_core.c | 5 +++++ test/test.answers | 8 ++++---- test/test100/proof.answer | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/cc_core.c b/cc_core.c index fc9a36a..8206e67 100644 --- a/cc_core.c +++ b/cc_core.c @@ -1085,6 +1085,7 @@ void process_if() require_match("ERROR in process_if\nMISSING )\n", ")"); statement(); + require(NULL != global_token, "Reached EOF inside of function\n"); if((KNIGHT_POSIX == Architecture) || (KNIGHT_NATIVE == Architecture)) emit_out("JUMP @_END_IF_"); else if(X86 == Architecture) emit_out("JUMP %_END_IF_"); @@ -1102,6 +1103,7 @@ void process_if() global_token = global_token->next; require(NULL != global_token, "Recieved EOF where an else statement expected\n"); statement(); + require(NULL != global_token, "Reached EOF inside of function\n"); } emit_out(":_END_IF_"); uniqueID_out(function->s, number_string); @@ -1171,6 +1173,7 @@ void process_for() require_match("ERROR in process_for\nMISSING )\n", ")"); statement(); + require(NULL != global_token, "Reached EOF inside of function\n"); if((KNIGHT_POSIX == Architecture) || (KNIGHT_NATIVE == Architecture)) emit_out("JUMP @FOR_ITER_"); else if(X86 == Architecture) emit_out("JUMP %FOR_ITER_"); @@ -1226,6 +1229,7 @@ void process_do() global_token = global_token->next; require(NULL != global_token, "Recieved EOF where do statement is expected\n"); statement(); + require(NULL != global_token, "Reached EOF inside of function\n"); require_match("ERROR in process_do\nMISSING while\n", "while"); require_match("ERROR in process_do\nMISSING (\n", "("); @@ -1284,6 +1288,7 @@ void process_while() require_match("ERROR in process_while\nMISSING )\n", ")"); statement(); + require(NULL != global_token, "Reached EOF inside of function\n"); if((KNIGHT_POSIX == Architecture) || (KNIGHT_NATIVE == Architecture)) emit_out("JUMP @WHILE_"); else if(X86 == Architecture) emit_out("JUMP %WHILE_"); diff --git a/test/test.answers b/test/test.answers index bd542fc..69b0c08 100644 --- a/test/test.answers +++ b/test/test.answers @@ -53,10 +53,10 @@ a0ae067746e7a2b01d33950da1cf640e12c3a70a045ab331ea2025af59dec9af test/results/t 1154f39f25dcd6d914e9a542306f95280926baf985d011b2152c7ea0b87ab42d test/results/test10-knight-native-binary c1b5a2a3cd46c5e95e5540e871c2a916e028684ca80f51c001ef489342e27625 test/results/test10-knight-posix-binary b3e13d54aab689137628fb9c4487bfd8288f9bd18bef8fe756577c8d2dce1f1f test/results/test10-x86-binary -61036eb3bc1b7039b5f6a240fb661728b57b0d16b641fa5f8d2740fe6b6e50e3 test/results/test100-amd64-binary -3987986885bfc3edb542b361b3f8d56f418b197f6974af2dcba320363faf24a6 test/results/test100-armv7l-binary -120233fe5773c21d83c40201cda4c858214593896919f62f42282cb5eb7b86e7 test/results/test100-knight-posix-binary -c7726290b1bd72e519da56e2a82a8fc11da22aecdd144e0498e7f2469c847649 test/results/test100-x86-binary +395269b9d4525c2be8da54db16d3a5874186e70c3623a18e6027ec88d5a82b59 test/results/test100-amd64-binary +c40d7ffcb22e7a6bfdfa8da047e73b2f7bfb24011f58ce79c5eea6f343ae2a32 test/results/test100-armv7l-binary +ac2be9c74cc0681ccf2b3413c84027233a63a7e733d740cd07cc3e51a2227008 test/results/test100-knight-posix-binary +e56280e3b896403a25791f189582195d7ad4d37654c2d30fba40e4505d2e8ea1 test/results/test100-x86-binary 34e6d535e30ef8826a4ad1a4d08b76cfa370c54595599ad3be784b64c9cd8ec5 test/results/test11-amd64-binary 893695e6f300a0fe055fad935a56abd549bba70d1d39c535a680f41bbb73f117 test/results/test11-armv7l-binary 955b564d2c89abf2cfc6c80d766cd11479d146b828dec69e654b0958a62d5e6e test/results/test11-knight-native-binary diff --git a/test/test100/proof.answer b/test/test100/proof.answer index b24b456..0df57ae 100644 --- a/test/test100/proof.answer +++ b/test/test100/proof.answer @@ -1 +1 @@ -c2e77ffce6bd293ef6f268626b7807dfbb05f0a8c17e9bd52f12c978a36fc830 test/test100/proof +b8a3169609d48a35a63fe7380f7de29a06ddc242a92475587cf78cc755cfb079 test/test100/proof