Fix sizeof string literals with zero byte
This commit is contained in:
parent
c529fc2b59
commit
c5dff3caf3
|
@ -1602,7 +1602,7 @@ Declaration * Parser::CopyConstantInitializer(int offset, Declaration* dtype, Ex
|
|||
return dec;
|
||||
}
|
||||
|
||||
uint8* Parser::ParseStringLiteral(int msize)
|
||||
uint8* Parser::ParseStringLiteral(int & msize)
|
||||
{
|
||||
int size = mScanner->mTokenStringSize;
|
||||
if (size + 1 > msize)
|
||||
|
@ -1843,13 +1843,13 @@ Expression* Parser::ParseInitExpression(Declaration* dtype)
|
|||
}
|
||||
else if (mScanner->mToken == TK_STRING && dtype->mType == DT_TYPE_ARRAY && dtype->mBase->mType == DT_TYPE_INTEGER && dtype->mBase->mSize == 1)
|
||||
{
|
||||
uint8* d = ParseStringLiteral(dtype->mSize);
|
||||
ptrdiff_t ds = strlen((char *)d);
|
||||
int ds = dtype->mSize;
|
||||
uint8* d = ParseStringLiteral(ds);
|
||||
|
||||
if (!(dtype->mFlags & DTF_DEFINED))
|
||||
{
|
||||
dtype->mFlags |= DTF_DEFINED;
|
||||
dtype->mSize = int(ds + 1);
|
||||
dtype->mSize = int(ds);
|
||||
}
|
||||
|
||||
dec = new Declaration(mScanner->mLocation, DT_CONST_DATA);
|
||||
|
@ -1859,7 +1859,7 @@ Expression* Parser::ParseInitExpression(Declaration* dtype)
|
|||
|
||||
dec->mData = d;
|
||||
|
||||
if (ds > dtype->mSize)
|
||||
if (ds > dtype->mSize + 1)
|
||||
mErrors->Error(mScanner->mLocation, EERR_CONSTANT_INITIALIZER, "String constant is too large for char array");
|
||||
}
|
||||
else
|
||||
|
|
|
@ -41,7 +41,7 @@ protected:
|
|||
void FreeTempVar(Declaration* var);
|
||||
void FreeTempVarExp(Expression* exp);
|
||||
|
||||
uint8* ParseStringLiteral(int msize);
|
||||
uint8* ParseStringLiteral(int & msize);
|
||||
|
||||
void ParseNamespace(void);
|
||||
|
||||
|
|
Loading…
Reference in New Issue