diff --git a/oscar64/Errors.h b/oscar64/Errors.h index a2f9fe1..73b80d0 100644 --- a/oscar64/Errors.h +++ b/oscar64/Errors.h @@ -16,6 +16,7 @@ enum ErrorID EWARN_GENERIC = 2000, EWARN_CONSTANT_TRUNCATED, EWARN_UNKNOWN_PRAGMA, + EWARN_INDEX_OUT_OF_BOUNDS, EWARN_SYNTAX, EERR_GENERIC = 3000, diff --git a/oscar64/InterCodeGenerator.cpp b/oscar64/InterCodeGenerator.cpp index 2004926..477722e 100644 --- a/oscar64/InterCodeGenerator.cpp +++ b/oscar64/InterCodeGenerator.cpp @@ -1119,6 +1119,16 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* vl = TranslateExpression(procType, proc, block, exp->mLeft, 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); vr = Dereference(proc, block, vr);