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;
|
return dec;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8* Parser::ParseStringLiteral(int msize)
|
uint8* Parser::ParseStringLiteral(int & msize)
|
||||||
{
|
{
|
||||||
int size = mScanner->mTokenStringSize;
|
int size = mScanner->mTokenStringSize;
|
||||||
if (size + 1 > msize)
|
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)
|
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);
|
int ds = dtype->mSize;
|
||||||
ptrdiff_t ds = strlen((char *)d);
|
uint8* d = ParseStringLiteral(ds);
|
||||||
|
|
||||||
if (!(dtype->mFlags & DTF_DEFINED))
|
if (!(dtype->mFlags & DTF_DEFINED))
|
||||||
{
|
{
|
||||||
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);
|
dec = new Declaration(mScanner->mLocation, DT_CONST_DATA);
|
||||||
|
@ -1859,7 +1859,7 @@ Expression* Parser::ParseInitExpression(Declaration* dtype)
|
||||||
|
|
||||||
dec->mData = d;
|
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");
|
mErrors->Error(mScanner->mLocation, EERR_CONSTANT_INITIALIZER, "String constant is too large for char array");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -41,7 +41,7 @@ protected:
|
||||||
void FreeTempVar(Declaration* var);
|
void FreeTempVar(Declaration* var);
|
||||||
void FreeTempVarExp(Expression* exp);
|
void FreeTempVarExp(Expression* exp);
|
||||||
|
|
||||||
uint8* ParseStringLiteral(int msize);
|
uint8* ParseStringLiteral(int & msize);
|
||||||
|
|
||||||
void ParseNamespace(void);
|
void ParseNamespace(void);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue