Add warning for constant out of bound array access
This commit is contained in:
parent
b415d02907
commit
9e7773a0f9
|
@ -16,6 +16,7 @@ enum ErrorID
|
||||||
EWARN_GENERIC = 2000,
|
EWARN_GENERIC = 2000,
|
||||||
EWARN_CONSTANT_TRUNCATED,
|
EWARN_CONSTANT_TRUNCATED,
|
||||||
EWARN_UNKNOWN_PRAGMA,
|
EWARN_UNKNOWN_PRAGMA,
|
||||||
|
EWARN_INDEX_OUT_OF_BOUNDS,
|
||||||
EWARN_SYNTAX,
|
EWARN_SYNTAX,
|
||||||
|
|
||||||
EERR_GENERIC = 3000,
|
EERR_GENERIC = 3000,
|
||||||
|
|
|
@ -1119,6 +1119,16 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
|
||||||
vl = TranslateExpression(procType, proc, block, exp->mLeft, breakBlock, continueBlock, inlineMapper);
|
vl = TranslateExpression(procType, proc, block, exp->mLeft, breakBlock, continueBlock, inlineMapper);
|
||||||
vr = TranslateExpression(procType, proc, block, exp->mRight, breakBlock, continueBlock, inlineMapper);
|
vr = TranslateExpression(procType, proc, block, exp->mRight, breakBlock, continueBlock, inlineMapper);
|
||||||
|
|
||||||
|
if (vl.mType->mType == DT_TYPE_ARRAY && exp->mRight->mType == EX_CONSTANT && exp->mRight->mDecValue->mType == DT_CONST_INTEGER)
|
||||||
|
{
|
||||||
|
if (vl.mType->mFlags & DTF_DEFINED)
|
||||||
|
{
|
||||||
|
int64 index = exp->mRight->mDecValue->mInteger;
|
||||||
|
if (index < 0 || index * vl.mType->mBase->mSize >= vl.mType->mSize)
|
||||||
|
mErrors->Error(exp->mLocation, EWARN_INDEX_OUT_OF_BOUNDS, "Constant array index out of bounds");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
vl = Dereference(proc, block, vl, vl.mType->mType == DT_TYPE_POINTER ? 0 : 1);
|
vl = Dereference(proc, block, vl, vl.mType->mType == DT_TYPE_POINTER ? 0 : 1);
|
||||||
vr = Dereference(proc, block, vr);
|
vr = Dereference(proc, block, vr);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue