Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes multi-dimesional array initilization bug #152

Merged
merged 1 commit into from
May 1, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions source/compiler/sc1.c
Original file line number Diff line number Diff line change
Expand Up @@ -2515,7 +2515,7 @@ static cell initarray(int ident,int tag,int dim[],int numdim,int cur,
constvalue *enumroot,int *errorfound)
{
cell dsize,totalsize;
int idx,idx_ellips,vidx;
int idx,idx_ellips,vidx, do_insert;
int abortparse;
int curlit;
cell *prev1=NULL,*prev2=NULL;
Expand All @@ -2525,7 +2525,13 @@ static cell initarray(int ident,int tag,int dim[],int numdim,int cur,
assert(cur+2<=numdim); /* there must be 2 dimensions or more to do */
assert(errorfound!=NULL && *errorfound==FALSE);
totalsize=0;
needtoken('{');
needtoken('{');
for (do_insert=0,idx=0; idx<=cur; idx++) {
if (dim[idx] == 0) {
do_insert = 1;
break;
} /* if */
} /* for */
for (idx=0,abortparse=FALSE; !abortparse; idx++) {
/* In case the major dimension is zero, we need to store the offset
* to the newly detected sub-array into the indirection table; i.e.
Expand All @@ -2535,7 +2541,7 @@ static cell initarray(int ident,int tag,int dim[],int numdim,int cur,
* necessary at this point to reserve space for an extra cell in the
* indirection vector.
*/
if (dim[cur]==0) {
if (do_insert) {
litinsert(0,startlit);
} else if (idx>=dim[cur]) {
error(18); /* initialization data exceeds array size */
Expand Down