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 memory corruption with multi-dimensional arrays #153

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
10 changes: 8 additions & 2 deletions source/compiler/sc1.c
Original file line number Diff line number Diff line change
Expand Up @@ -2456,12 +2456,18 @@ static void initials(int ident,int tag,cell *size,int dim[],int numdim,
constvalue lastdim={NULL,"",0,0}; /* sizes of the final dimension */
int skipdim=0;

if (dim[numdim-1]!=0)
*size=calc_arraysize(dim,numdim,0); /* calc. full size, if known */
/* check if the user has given the size of all dimensions */
for (idx = 0; idx < numdim; idx++)
if (dim[idx] == 0)
break;
/* already reserve space for the indirection tables (for an array with
* known dimensions)
* (do not use dumpzero(), as it bypasses the literal queue)
*/
if(idx == numdim)
*size=calc_arraysize(dim,numdim,0); /* user has provided the size of all the dimensions, so calculate the size */
else
*size = 0; /* user hasn't given the size for one or more dimensions */
for (tablesize=calc_arraysize(dim,numdim-1,0); tablesize>0; tablesize--)
litadd(0);
/* now initialize the sub-arrays */
Expand Down