Fix trailing commas in array literals changing the result of sizeof()
This commit is contained in:
		| @@ -370,8 +370,9 @@ typedef struct s_stringpair { | ||||
| #define tSYMBOL  330 | ||||
| #define tLABEL   331 | ||||
| #define tSTRING  332 | ||||
| #define tEXPR    333    /* for assigment to "lastst" only */ | ||||
| #define tEMPTYBLOCK 334 /* empty blocks for AM bug 4825 */ | ||||
| #define tPENDING_STRING 333 | ||||
| #define tEXPR    334    /* for assigment to "lastst" only */ | ||||
| #define tEMPTYBLOCK 335 /* empty blocks for AM bug 4825 */ | ||||
|  | ||||
| /* (reversed) evaluation of staging buffer */ | ||||
| #define sSTARTREORDER 0x01 | ||||
| @@ -811,6 +812,8 @@ SC_VDECL FILE *outf;          /* file written to */ | ||||
|  | ||||
| SC_VDECL jmp_buf errbuf;      /* target of longjmp() on a fatal error */ | ||||
|  | ||||
| SC_VDECL SC_VDEFINE char sLiteralQueueDisabled; | ||||
|  | ||||
| #if !defined SC_LIGHT | ||||
|   SC_VDECL int sc_makereport; /* generate a cross-reference report */ | ||||
| #endif | ||||
|   | ||||
| @@ -2296,6 +2296,7 @@ static cell initarray(int ident,int tag,int dim[],int numdim,int cur, | ||||
| { | ||||
|   cell dsize,totalsize; | ||||
|   int idx,abortparse; | ||||
|   static char disable = FALSE; | ||||
|  | ||||
|   assert(cur>=0 && cur<numdim); | ||||
|   assert(startlit>=0); | ||||
| @@ -2332,6 +2333,13 @@ static cell initarray(int ident,int tag,int dim[],int numdim,int cur, | ||||
|     totalsize+=dsize; | ||||
|     if (*errorfound || !matchtoken(',')) | ||||
|       abortparse=TRUE; | ||||
|     disable = sLiteralQueueDisabled; | ||||
|     sLiteralQueueDisabled = TRUE; | ||||
|     if (matchtoken('}')) { | ||||
|       abortparse = TRUE; | ||||
|       lexpush(); | ||||
|     } | ||||
|     sLiteralQueueDisabled = disable; | ||||
|   } /* for */ | ||||
|   needtoken('}'); | ||||
|   assert(counteddim!=NULL); | ||||
|   | ||||
| @@ -1857,7 +1857,7 @@ char *sc_tokens[] = { | ||||
|          "#endscript", "#error", "#file", "#if", "#include", "#line", "#pragma", | ||||
|          "#tryinclude", "#undef", | ||||
|          ";", ";", "-integer value-", "-rational value-", "-identifier-", | ||||
|          "-label-", "-string-" | ||||
|          "-label-", "-string-", "-string-" | ||||
|        }; | ||||
|  | ||||
| SC_FUNC int lex(cell *lexvalue,char **lexsym) | ||||
| @@ -1976,6 +1976,10 @@ SC_FUNC int lex(cell *lexvalue,char **lexsym) | ||||
|     } /* if */ | ||||
|   } else if (*lptr=='\"' || (*lptr==sc_ctrlchar && *(lptr+1)=='\"')) | ||||
|   {                                     /* unpacked string literal */ | ||||
|     if (sLiteralQueueDisabled) { | ||||
|       _lextok=tPENDING_STRING; | ||||
|       return _lextok; | ||||
|     } | ||||
|     _lextok=tSTRING; | ||||
|     stringflags= (*lptr==sc_ctrlchar) ? RAWMODE : 0; | ||||
|     *lexvalue=_lexval=litidx; | ||||
| @@ -2045,6 +2049,10 @@ SC_FUNC int lex(cell *lexvalue,char **lexsym) | ||||
|  */ | ||||
| SC_FUNC void lexpush(void) | ||||
| { | ||||
|   if (_lextok == tPENDING_STRING) { | ||||
|     // Don't push back fake tokens. | ||||
|     return; | ||||
|   } | ||||
|   assert(_pushed==FALSE); | ||||
|   _pushed=TRUE; | ||||
| } | ||||
| @@ -2204,6 +2212,7 @@ static void chk_grow_litq(void) | ||||
|  */ | ||||
| SC_FUNC void litadd(cell value) | ||||
| { | ||||
|   assert(!sLiteralQueueDisabled); | ||||
|   chk_grow_litq(); | ||||
|   assert(litidx<litmax); | ||||
|   litq[litidx++]=value; | ||||
| @@ -2219,6 +2228,7 @@ SC_FUNC void litadd(cell value) | ||||
|  */ | ||||
| SC_FUNC void litinsert(cell value,int pos) | ||||
| { | ||||
|   assert(!sLiteralQueueDisabled); | ||||
|   chk_grow_litq(); | ||||
|   assert(litidx<litmax); | ||||
|   assert(pos>=0 && pos<=litidx); | ||||
|   | ||||
| @@ -100,6 +100,8 @@ SC_VDEFINE jmp_buf errbuf; | ||||
|  | ||||
| SC_VDEFINE HashTable *sp_Globals = NULL; | ||||
|  | ||||
| SC_VDEFINE char sLiteralQueueDisabled = FALSE; | ||||
|  | ||||
| #if !defined SC_LIGHT | ||||
|   SC_VDEFINE int sc_makereport=FALSE; /* generate a cross-reference report */ | ||||
| #endif | ||||
|   | ||||
		Reference in New Issue
	
	Block a user