diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index 655678b..616da3c 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -2490,17 +2490,21 @@ static void initials(int ident,int tag,cell *size,int dim[],int numdim, cell tablesize; int curlit=litidx; int err=0; + int i; if (!matchtoken('=')) { assert(ident!=iARRAY || numdim>0); - if (ident==iARRAY && dim[numdim-1]==0) { - /* declared as "myvar[];" which is senseless (note: this *does* make - * sense in the case of a iREFARRAY, which is a function parameter) - */ - error(9); /* array has zero length -> invalid size */ - } /* if */ if (ident==iARRAY) { assert(numdim>0 && numdim<=sDIMEN_MAX); + for (i=0; i invalid size */ + return; + } /* if */ + } /* for */ *size=calc_arraysize(dim,numdim,0); if (*size==(cell)CELL_MAX) { error(9); /* array is too big -> invalid size */ diff --git a/source/compiler/tests/CMakeLists.txt b/source/compiler/tests/CMakeLists.txt index 7f92852..02110b4 100644 --- a/source/compiler/tests/CMakeLists.txt +++ b/source/compiler/tests/CMakeLists.txt @@ -70,6 +70,16 @@ set_tests_properties(const_array_args_and_literals_gh_276 PROPERTIES PASS_REGULA .*\\.pwn\\(41\\) : warning 239: literal array/string passed to a non-const parameter ") +add_compiler_test(md_array_size_chk_gh_314 ${CMAKE_CURRENT_SOURCE_DIR}/md_array_size_chk_gh_314.pwn) +set_tests_properties(md_array_size_chk_gh_314 PROPERTIES PASS_REGULAR_EXPRESSION +"*\\.pwn\\(1\\) : error 009: invalid array size \\(negative, zero or out of bounds\\) +.*\\.pwn\\(2\\) : error 009: invalid array size \\(negative, zero or out of bounds\\) +.*\\.pwn\\(3\\) : error 009: invalid array size \\(negative, zero or out of bounds\\) +.*\\.pwn\\(5\\) : error 009: invalid array size \\(negative, zero or out of bounds\\) +.*\\.pwn\\(30\\) : warning 224: indeterminate array size in \"sizeof\" expression \\(symbol \"\"\\) +") +set_tests_properties(md_array_size_chk_gh_314 PROPERTIES WILL_FAIL TRUE) + add_compiler_test(destructor_not_impl_gh_310 ${CMAKE_CURRENT_SOURCE_DIR}/destructor_not_impl_gh_310.pwn) set_tests_properties(destructor_not_impl_gh_310 PROPERTIES PASS_REGULAR_EXPRESSION ".*\\.pwn\\(6\\) : error 004: function \"operator~(Error:)\" is not implemented diff --git a/source/compiler/tests/md_array_size_chk_gh_314.pwn b/source/compiler/tests/md_array_size_chk_gh_314.pwn new file mode 100644 index 0000000..368833d --- /dev/null +++ b/source/compiler/tests/md_array_size_chk_gh_314.pwn @@ -0,0 +1,40 @@ +new arr1[] = {}; +new arr2[5][]; +new arr3[5][][5]; +new arr4[5][5]; +new arr5[][]= { { } }; + +f1(arr[]) { + #pragma unused arr +} +f2(arr[5][]) { + #pragma unused arr +} +f3(arr[5][][5]) { + #pragma unused arr +} +f4(arr[5][5]) { + #pragma unused arr +} +f5(arr[][]) { + #pragma unused arr +} + +main () { + arr1[0] = 0; + arr2[0][0] = 0; + arr3[0][0][0] = 0; + arr4[0][0] = 0; + arr5[0][0] = 0; + + new a = sizeof(arr1); + a = sizeof(arr1[]); + a = sizeof(arr5[][]); + #pragma unused a + + f1(arr1); + f2(arr2); + f3(arr3); + f4(arr4); + f5(arr5); +}