From 8bc09f2b2ee9d3f78bb48d7b8129898ab037b5f6 Mon Sep 17 00:00:00 2001 From: Jeremiah Orians Date: Wed, 23 Jun 2021 07:32:40 -0400 Subject: [PATCH] Fixed hang on large global arrays. Thanks melg8 --- CHANGELOG.org | 1 + cc_core.c | 13 +++++++++---- test/test.answers | 10 +++++----- test/test1000/proof.answer | 2 +- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.org b/CHANGELOG.org index f71c23d..e9b4901 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -20,6 +20,7 @@ ** Changed ** Fixed +Stop hang on large global arrays ** Removed diff --git a/cc_core.c b/cc_core.c index 6dafa0e..135da76 100644 --- a/cc_core.c +++ b/cc_core.c @@ -1920,6 +1920,15 @@ new_type: /* length */ size = strtoint(global_token->s); + + /* Ensure properly closed */ + global_token = global_token->next; + require_match("missing close bracket\n", "]"); + require_match("missing ;\n", ";"); + + /* Stop bad states */ + require(size > 0, "Negative values are not supported\n"); + require(size < 4096, "M2-Planet is very inefficient so you probably don't want to allocate 4+K bytes into your binary for NULLs\n"); globals_list = emit("\n'", globals_list); while (0 != size) { @@ -1928,10 +1937,6 @@ new_type: } globals_list = emit("'\n", globals_list); - global_token = global_token->next; - require_match("missing close bracket\n", "]"); - require_match("missing ;\n", ";"); - goto new_type; } /* Add to global symbol table */ diff --git a/test/test.answers b/test/test.answers index 93195a6..9d5a223 100644 --- a/test/test.answers +++ b/test/test.answers @@ -179,8 +179,8 @@ fc31fc8b2d78bd50a4c89eb0e29149626868a70842a3dcb01ea87bb275a9e3c2 test/results/t 965bdf7049179199b9f423250a186c7b64ea55326c3249127d2daf7d42ae53cc test/results/test0106-knight-native-binary 0a929d6990caee3e93b1188a38fd3041c6f8e46d25a386024647c0f05c33bce7 test/results/test0106-knight-posix-binary 331ffb5284bd824494ad61a3b0b2dff5681a63ab604e9a06100af531ae237148 test/results/test0106-x86-binary -b059b96414cf326cf211c3b1d63eb01a15924a3c60964ed2e583856715e522fa test/results/test1000-aarch64-binary -c257acf49baa7335f29fd08dcc33986734bb11217b9489f908ec1a46ac228837 test/results/test1000-amd64-binary -0ecdeb7ff165e675d30973906691d02cf2a3a9486d4d3e4da1074e1b8e58dbf7 test/results/test1000-armv7l-binary -423b5e50018d464c62c6a5fc4384cb716f56a07ad434c32e7adc6a4446ebcb4c test/results/test1000-knight-posix-binary -989b624d9a37aae9a92286542d45450775bcbb924667a4e7a975834e5e85050b test/results/test1000-x86-binary +e9d19ffdb968df9acf74803992ddeaeb8cdac0859c376874aff7c511da8152f1 test/results/test1000-aarch64-binary +b7bf60cfdbc7307b012ce37f7db9dce1232742ba2e024727659421ea569cabff test/results/test1000-amd64-binary +eab68643534484930e46a7e80530323cb6846b732ecb01d868cc162c239bf1a6 test/results/test1000-armv7l-binary +75223a8ee5a44debdf45244e3862bdaebae0723c093baa38dd92e91241bbeb0e test/results/test1000-knight-posix-binary +4919f426e681405958ad576c718dcb2fd3ade32e73b367e28c071503485c7475 test/results/test1000-x86-binary diff --git a/test/test1000/proof.answer b/test/test1000/proof.answer index bf1bad0..6b1f159 100644 --- a/test/test1000/proof.answer +++ b/test/test1000/proof.answer @@ -1 +1 @@ -1b63f8b58ff8758d46629d57e45c97fc95bab326603107689883ba6aef0a77cc test/test1000/proof +5d15d5c7db17f5341d10f5d459af1bc62b77e60b59ca05aed3d8dbcb920a40f4 test/test1000/proof