From 314f3401c8a74c4afa1dfc21663cd9d1f2bd9c1f Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sat, 17 Feb 2007 04:37:47 +0000 Subject: [PATCH] fixed a bug where determinate 1D arrays would not have correct sizeof() -- REALLY hacky fix :( fixed local arrays asserting on more than two dimensions with the last dimension being indeterminate --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40516 --- sourcepawn/compiler/sc.h | 1 + sourcepawn/compiler/sc1.c | 10 ++++++++++ sourcepawn/compiler/sc2.c | 12 +++++++++--- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/sourcepawn/compiler/sc.h b/sourcepawn/compiler/sc.h index 95f61483..2b3783ac 100644 --- a/sourcepawn/compiler/sc.h +++ b/sourcepawn/compiler/sc.h @@ -823,6 +823,7 @@ SC_VDECL int pc_optimize; /* (peephole) optimization level */ SC_VDECL int pc_memflags; /* special flags for the stack/heap usage */ SC_VDECL int pc_functag; /* global function tag */ SC_VDECL int pc_tag_string; /* global string tag */ +SC_VDECL int glbstringread; /* last global string read */ SC_VDECL constvalue sc_automaton_tab; /* automaton table */ SC_VDECL constvalue sc_state_tab; /* state table */ diff --git a/sourcepawn/compiler/sc1.c b/sourcepawn/compiler/sc1.c index b9e4ed34..fce03a4f 100644 --- a/sourcepawn/compiler/sc1.c +++ b/sourcepawn/compiler/sc1.c @@ -170,6 +170,7 @@ static int *wqptr; /* pointer to next entry */ static HWND hwndFinish = 0; #endif +SC_VDECL int glbstringread = 0; char g_tmpfile[_MAX_PATH] = {0}; /* "main" of the compiler @@ -2044,6 +2045,9 @@ static void declglb(char *firstname,int firsttag,int fpublic,int fstatic,int fst } /* if */ assert(litidx==0); /* literal queue should be empty (again) */ initials(ident,tag,&size,dim,numdim,enumroot);/* stores values in the literal queue */ + if (tag == pc_tag_string && (numdim == 1) && !dim[numdim-1]) { + slength = glbstringread; + } assert(size>=litidx); if (numdim==1) dim[0]=(int)size; @@ -2209,6 +2213,7 @@ static int declloc(int fstatic) do { ident=iVARIABLE; size=1; + slength=0; numdim=0; /* no dimensions */ tag=pc_addtag(NULL); if (lex(&val,&str)!=tSYMBOL) /* read in (new) token */ @@ -2304,7 +2309,12 @@ static int declloc(int fstatic) sc_alignnext=FALSE; } /* if */ cur_lit=litidx; /* save current index in the literal table */ + if (numdim && !dim[numdim-1]) + size = 0; initials(ident,tag,&size,dim,numdim,enumroot); + if (tag == pc_tag_string && (numdim == 1) && !dim[numdim-1]) { + slength = glbstringread; + } if (size==0) return ident; /* error message already given */ if (numdim==1) diff --git a/sourcepawn/compiler/sc2.c b/sourcepawn/compiler/sc2.c index 2894e14c..a0609c6f 100644 --- a/sourcepawn/compiler/sc2.c +++ b/sourcepawn/compiler/sc2.c @@ -1798,6 +1798,7 @@ static const unsigned char *packedstring(const unsigned char *lptr,int flags) i=0; /* start at least significant byte */ val=0; + glbstringread=1; while (*lptr!='\"' && *lptr!='\0') { if (*lptr=='\a') { /* ignore '\a' (which was inserted at a line concatenation) */ lptr++; @@ -1807,6 +1808,7 @@ static const unsigned char *packedstring(const unsigned char *lptr,int flags) if (c>=(ucell)(1 << sCHARBITS)) error(43); /* character constant exceeds range */ val |= (c << 8*i); + glbstringread++; if (i==sizeof(ucell)-(sCHARBITS/8)) { litadd(val); val=0; @@ -2821,10 +2823,14 @@ SC_FUNC symbol *addvariable2(const char *name,cell addr,int ident,int vclass,int for (level=0; leveldim.array.length=dim[level]; - if (tag == pc_tag_string && level == numdim - 1) - top->dim.array.slength=slength; - else + if (tag == pc_tag_string && level == numdim - 1) { + if (slength == 0) + top->dim.array.length=dim[level] * sizeof(cell); + else + top->dim.array.slength=slength; + } else { top->dim.array.slength=0; + } top->dim.array.level=(short)(numdim-level-1); top->x.tags.index=idxtag[level]; top->parent=parent;