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