Fix trailing commas in array literals changing the result of sizeof().
This commit is contained in:
parent
4c377f21f9
commit
099f299113
@ -464,6 +464,7 @@ enum TokenKind {
|
|||||||
tSYMBOL,
|
tSYMBOL,
|
||||||
tLABEL,
|
tLABEL,
|
||||||
tSTRING,
|
tSTRING,
|
||||||
|
tPENDING_STRING, /* string, but not yet dequeued */
|
||||||
tEXPR, /* for assigment to "lastst" only (see SC1.C) */
|
tEXPR, /* for assigment to "lastst" only (see SC1.C) */
|
||||||
tENDLESS, /* endless loop, for assigment to "lastst" only */
|
tENDLESS, /* endless loop, for assigment to "lastst" only */
|
||||||
tEMPTYBLOCK, /* empty blocks for AM bug 4825 */
|
tEMPTYBLOCK, /* empty blocks for AM bug 4825 */
|
||||||
@ -960,4 +961,14 @@ enum FatalError {
|
|||||||
FATAL_ERRORS_TOTAL
|
FATAL_ERRORS_TOTAL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct AutoDisableLiteralQueue
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AutoDisableLiteralQueue();
|
||||||
|
~AutoDisableLiteralQueue();
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool prev_value_;
|
||||||
|
};
|
||||||
|
|
||||||
#endif /* SC_H_INCLUDED */
|
#endif /* SC_H_INCLUDED */
|
||||||
|
@ -2716,6 +2716,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;
|
||||||
|
{
|
||||||
|
// We need this since, lex() could add a string to the literal queue,
|
||||||
|
// which totally messes up initvector's state tracking. What a mess.
|
||||||
|
AutoDisableLiteralQueue disable;
|
||||||
|
if (lexpeek('}'))
|
||||||
|
abortparse=TRUE;
|
||||||
|
}
|
||||||
} /* for */
|
} /* for */
|
||||||
needtoken('}');
|
needtoken('}');
|
||||||
assert(counteddim!=NULL);
|
assert(counteddim!=NULL);
|
||||||
|
@ -69,6 +69,18 @@ static double pow10(double d)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static bool sLiteralQueueDisabled = false;
|
||||||
|
|
||||||
|
AutoDisableLiteralQueue::AutoDisableLiteralQueue()
|
||||||
|
: prev_value_(sLiteralQueueDisabled)
|
||||||
|
{
|
||||||
|
sLiteralQueueDisabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
AutoDisableLiteralQueue::~AutoDisableLiteralQueue()
|
||||||
|
{
|
||||||
|
sLiteralQueueDisabled = prev_value_;
|
||||||
|
}
|
||||||
|
|
||||||
/* pushstk & popstk
|
/* pushstk & popstk
|
||||||
*
|
*
|
||||||
@ -1969,7 +1981,7 @@ const 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-"
|
||||||
};
|
};
|
||||||
|
|
||||||
static full_token_t *advance_token_ptr()
|
static full_token_t *advance_token_ptr()
|
||||||
@ -2137,6 +2149,11 @@ int lex(cell *lexvalue,char **lexsym)
|
|||||||
#endif
|
#endif
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
if (sLiteralQueueDisabled) {
|
||||||
|
tok->id = tPENDING_STRING;
|
||||||
|
tok->end = tok->start;
|
||||||
|
return tok->id;
|
||||||
|
}
|
||||||
int stringflags,segmentflags;
|
int stringflags,segmentflags;
|
||||||
char *cat;
|
char *cat;
|
||||||
tok->id = tSTRING;
|
tok->id = tSTRING;
|
||||||
@ -2261,6 +2278,11 @@ int lex(cell *lexvalue,char **lexsym)
|
|||||||
*/
|
*/
|
||||||
void lexpush(void)
|
void lexpush(void)
|
||||||
{
|
{
|
||||||
|
if (current_token()->id == tPENDING_STRING) {
|
||||||
|
// Don't push back fake tokens.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
assert(sTokenBuffer->depth < MAX_TOKEN_DEPTH);
|
assert(sTokenBuffer->depth < MAX_TOKEN_DEPTH);
|
||||||
sTokenBuffer->depth++;
|
sTokenBuffer->depth++;
|
||||||
if (sTokenBuffer->cursor == 0)
|
if (sTokenBuffer->cursor == 0)
|
||||||
@ -2484,6 +2506,7 @@ static void chk_grow_litq(void)
|
|||||||
*/
|
*/
|
||||||
void litadd(cell value)
|
void litadd(cell value)
|
||||||
{
|
{
|
||||||
|
assert(!sLiteralQueueDisabled);
|
||||||
chk_grow_litq();
|
chk_grow_litq();
|
||||||
assert(litidx<litmax);
|
assert(litidx<litmax);
|
||||||
litq[litidx++]=value;
|
litq[litidx++]=value;
|
||||||
@ -2499,6 +2522,7 @@ void litadd(cell value)
|
|||||||
*/
|
*/
|
||||||
void litinsert(cell value,int pos)
|
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);
|
||||||
|
Loading…
Reference in New Issue
Block a user