Skip to content

Commit bdf053c

Browse files
committed
Test (and error) for a multidimensional array with zero size; copied from wowcube.
1 parent fe73a74 commit bdf053c

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

compiler/sc1.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ int pc_compile(int argc, char *argv[])
688688
spawnl(P_WAIT,pgmname,pgmname,reportname,dotname,NULL);
689689
#else
690690
snprintf(pgmname,sizearray(pgmname),"%s%cstategraph",sc_binpath,DIRSEP_CHAR);
691-
posix_spawnl(pgmname,reportname,dotname,(char*)NULL);
691+
posix_spawnl(pgmname,reportname,dotname,NULL);
692692
#endif
693693
}
694694
} /* if */
@@ -2755,19 +2755,23 @@ static void initials(int ident,int usage,int tag,cell *size,int dim[],int numdim
27552755
if (!matchtoken('=')) {
27562756
cell tablesize;
27572757
assert(ident!=iARRAY || numdim>0);
2758-
if (ident==iARRAY && dim[numdim-1]==0) {
2759-
/* declared as "myvar[];" which is senseless (note: this *does* make
2760-
* sense in the case of a iREFARRAY, which is a function parameter)
2761-
*/
2762-
error(9); /* array has zero length -> invalid size */
2763-
} /* if */
27642758
if (ident==iARRAY) {
2759+
int i;
27652760
assert(numdim>0 && numdim<=sDIMEN_MAX);
2761+
for (i=0; i<numdim; i++) {
2762+
if (dim[i]==0) {
2763+
/* any of array size is zero which is senseless (note: this *does* make
2764+
* sense in the case of a iREFARRAY, which is a function parameter)
2765+
*/
2766+
error(9); /* array has zero length -> invalid size */
2767+
return;
2768+
}
2769+
}
27662770
*size=calc_arraysize(dim,numdim,0);
27672771
if (*size==(cell)CELL_MAX) {
27682772
error(9); /* array is too big -> invalid size */
27692773
return;
2770-
} /* if */
2774+
}
27712775
/* first reserve space for the indirection vectors of the array, then
27722776
* adjust it to contain the proper values
27732777
* (do not use dumpzero(), as it bypasses the literal queue)

test/test.rexx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,3 +1961,13 @@ test154:
19611961
pawncc '-; EMPTY_MAIN= test14'
19621962
return
19631963

1964+
test155:
1965+
say '155. The compilation should issue error 009 (invalid array size).'
1966+
say ''
1967+
say ' An array with major dimension of zero and valid minor dimension".'
1968+
say ''
1969+
say 'Symptoms of detected bug: no error, but failed on an assertion later on.'
1970+
say '-----'
1971+
pawncc 'ZERO_ARRAY_TWO_DIMS= test1'
1972+
return
1973+

test/test1.p

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ new Filenames[6]{} =
209209
new port = readcfgvalue(.key = "proxy-port", .filename = config_network)
210210
#endif
211211

212+
#if defined ZERO_ARRAY_TWO_DIMS
213+
new array[0][1];
214+
#endif
215+
212216
main()
213217
{
214218
#if defined UNDEF_FUNC_CALL
@@ -567,6 +571,10 @@ main()
567571
#pragma warning pop
568572
b = b;
569573
#endif
574+
575+
#if defined ZERO_ARRAY_TWO_DIMS
576+
array[0][0]=0
577+
#endif
570578
}
571579

572580
#if defined LOCAL_SHADOWS
@@ -601,3 +609,4 @@ forward dummyfunc()
601609
public dummyfunc()
602610
return 0
603611
#endif
612+

0 commit comments

Comments
 (0)