Add warning for out of bounds accesses
This commit is contained in:
parent
2c1a87ce02
commit
3992b1d547
|
@ -1263,7 +1263,7 @@ bool Compiler::WriteOutputFile(const char* targetPath, DiskImage * d64)
|
|||
|
||||
if (mCompilerOptions & COPT_VERBOSE)
|
||||
printf("Writing <%s>\n", asmPath);
|
||||
mLinker->WriteAsmFile(asmPath);
|
||||
mLinker->WriteAsmFile(asmPath, mVersion);
|
||||
|
||||
if (mCompilerOptions & COPT_VERBOSE)
|
||||
printf("Writing <%s>\n", lblPath);
|
||||
|
|
|
@ -34,6 +34,7 @@ public:
|
|||
TargetMachine mTargetMachine;
|
||||
uint64 mCompilerOptions;
|
||||
uint16 mCartridgeID;
|
||||
char mVersion[32];
|
||||
|
||||
struct Define
|
||||
{
|
||||
|
|
|
@ -3386,7 +3386,7 @@ void InterInstruction::FilterStaticVarsUsage(const GrowingVariableArray& staticV
|
|||
}
|
||||
}
|
||||
|
||||
void InterInstruction::FilterStaticVarsByteUsage(const GrowingVariableArray& staticVars, NumberSet& requiredVars, NumberSet& providedVars)
|
||||
void InterInstruction::FilterStaticVarsByteUsage(const GrowingVariableArray& staticVars, NumberSet& requiredVars, NumberSet& providedVars, Errors* errors)
|
||||
{
|
||||
if (mCode == IC_LOAD)
|
||||
{
|
||||
|
@ -3403,8 +3403,13 @@ void InterInstruction::FilterStaticVarsByteUsage(const GrowingVariableArray& sta
|
|||
}
|
||||
else if (mSrc[0].mMemory == IM_GLOBAL)
|
||||
{
|
||||
if (mSrc[0].mVarIndex >= 0 && !providedVars.RangeFilled(staticVars[mSrc[0].mVarIndex]->mByteIndex + int(mSrc[0].mIntConst), InterTypeSize[mDst.mType]))
|
||||
requiredVars.AddRange(staticVars[mSrc[0].mVarIndex]->mByteIndex + int(mSrc[0].mIntConst), InterTypeSize[mDst.mType]);
|
||||
if (mSrc[0].mVarIndex >= 0)
|
||||
{
|
||||
if (int(mSrc[0].mIntConst) < 0 || int(mSrc[0].mIntConst) + InterTypeSize[mDst.mType] > staticVars[mSrc[0].mVarIndex]->mSize)
|
||||
errors->Error(mLocation, EWARN_INDEX_OUT_OF_BOUNDS, "Index out of bounds");
|
||||
else if (!providedVars.RangeFilled(staticVars[mSrc[0].mVarIndex]->mByteIndex + int(mSrc[0].mIntConst), InterTypeSize[mDst.mType]))
|
||||
requiredVars.AddRange(staticVars[mSrc[0].mVarIndex]->mByteIndex + int(mSrc[0].mIntConst), InterTypeSize[mDst.mType]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (mCode == IC_STORE)
|
||||
|
@ -3415,7 +3420,12 @@ void InterInstruction::FilterStaticVarsByteUsage(const GrowingVariableArray& sta
|
|||
else if (mSrc[1].mMemory == IM_GLOBAL)
|
||||
{
|
||||
if (mSrc[1].mVarIndex >= 0)
|
||||
providedVars.AddRange(staticVars[mSrc[1].mVarIndex]->mByteIndex + int(mSrc[1].mIntConst), InterTypeSize[mSrc[0].mType]);
|
||||
{
|
||||
if (int(mSrc[1].mIntConst) < 0 || int(mSrc[1].mIntConst) + InterTypeSize[mSrc[0].mType] > staticVars[mSrc[1].mVarIndex]->mSize)
|
||||
errors->Error(mLocation, EWARN_INDEX_OUT_OF_BOUNDS, "Index out of bounds");
|
||||
else
|
||||
providedVars.AddRange(staticVars[mSrc[1].mVarIndex]->mByteIndex + int(mSrc[1].mIntConst), InterTypeSize[mSrc[0].mType]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (mCode == IC_COPY || mCode == IC_CALL || mCode == IC_CALL_NATIVE || mCode == IC_RETURN || mCode == IC_RETURN_STRUCT || mCode == IC_RETURN_VALUE || mCode == IC_STRCPY || mCode == IC_DISPATCH)
|
||||
|
@ -9121,7 +9131,7 @@ void InterCodeBasicBlock::BuildStaticVariableByteSet(const GrowingVariableArray&
|
|||
mExitProvidedStatics.Reset(bsize);
|
||||
|
||||
for (int i = 0; i < mInstructions.Size(); i++)
|
||||
mInstructions[i]->FilterStaticVarsByteUsage(staticVars, mLocalRequiredStatics, mLocalProvidedStatics);
|
||||
mInstructions[i]->FilterStaticVarsByteUsage(staticVars, mLocalRequiredStatics, mLocalProvidedStatics, mProc->mModule->mErrors);
|
||||
|
||||
mEntryRequiredStatics = mLocalRequiredStatics;
|
||||
mExitProvidedStatics = mLocalProvidedStatics;
|
||||
|
|
|
@ -321,7 +321,7 @@ public:
|
|||
void FilterTempUsage(NumberSet& requiredTemps, NumberSet& providedTemps);
|
||||
void FilterVarsUsage(const GrowingVariableArray& localVars, NumberSet& requiredVars, NumberSet& providedVars, const GrowingVariableArray& params, NumberSet& requiredParams, NumberSet& providedParams, InterMemory paramMemory);
|
||||
void FilterStaticVarsUsage(const GrowingVariableArray& staticVars, NumberSet& requiredVars, NumberSet& providedVars);
|
||||
void FilterStaticVarsByteUsage(const GrowingVariableArray& staticVars, NumberSet& requiredVars, NumberSet& providedVars);
|
||||
void FilterStaticVarsByteUsage(const GrowingVariableArray& staticVars, NumberSet& requiredVars, NumberSet& providedVars, Errors * errors);
|
||||
|
||||
bool RemoveUnusedResultInstructions(InterInstruction* pre, NumberSet& requiredTemps);
|
||||
bool RemoveUnusedStoreInstructions(const GrowingVariableArray& localVars, NumberSet& requiredVars, const GrowingVariableArray& params, NumberSet& requiredParams, InterMemory paramMemory);
|
||||
|
|
|
@ -1706,12 +1706,14 @@ bool Linker::WriteLblFile(const char* filename)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool Linker::WriteAsmFile(const char* filename)
|
||||
bool Linker::WriteAsmFile(const char* filename, const char* version)
|
||||
{
|
||||
FILE* file;
|
||||
fopen_s(&file, filename, "wb");
|
||||
if (file)
|
||||
{
|
||||
fprintf(file, "; Compiled with %s\n", version);
|
||||
|
||||
for (int i = 0; i < mObjects.Size(); i++)
|
||||
{
|
||||
LinkerObject* obj = mObjects[i];
|
||||
|
|
|
@ -269,7 +269,7 @@ public:
|
|||
bool WritePrgFile(const char* filename);
|
||||
bool WriteXexFile(const char* filename);
|
||||
bool WriteMapFile(const char* filename);
|
||||
bool WriteAsmFile(const char* filename);
|
||||
bool WriteAsmFile(const char* filename, const char * version);
|
||||
bool WriteLblFile(const char* filename);
|
||||
bool WriteCrtFile(const char* filename, uint16 id);
|
||||
bool WriteBinFile(const char* filename);
|
||||
|
|
|
@ -74,7 +74,7 @@ int main2(int argc, const char** argv)
|
|||
|
||||
#else
|
||||
strcpy(strProductName, "oscar64");
|
||||
strcpy(strProductVersion, "1.26.231");
|
||||
strcpy(strProductVersion, "1.26.232");
|
||||
|
||||
#ifdef __APPLE__
|
||||
uint32_t length = sizeof(basePath);
|
||||
|
@ -459,6 +459,8 @@ int main2(int argc, const char** argv)
|
|||
|
||||
if (compiler->mErrors->mErrorCount == 0)
|
||||
{
|
||||
strcpy_s(compiler->mVersion, strProductVersion);
|
||||
|
||||
if (compiler->mCompilerOptions & COPT_VERBOSE)
|
||||
{
|
||||
printf("Starting %s %s\n", strProductName, strProductVersion);
|
||||
|
|
|
@ -25,8 +25,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL
|
|||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,26,231,0
|
||||
PRODUCTVERSION 1,26,231,0
|
||||
FILEVERSION 1,26,232,0
|
||||
PRODUCTVERSION 1,26,232,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
|
@ -43,12 +43,12 @@ BEGIN
|
|||
BEGIN
|
||||
VALUE "CompanyName", "oscar64"
|
||||
VALUE "FileDescription", "oscar64 compiler"
|
||||
VALUE "FileVersion", "1.26.231.0"
|
||||
VALUE "FileVersion", "1.26.232.0"
|
||||
VALUE "InternalName", "oscar64.exe"
|
||||
VALUE "LegalCopyright", "Copyright (C) 2021"
|
||||
VALUE "OriginalFilename", "oscar64.exe"
|
||||
VALUE "ProductName", "oscar64"
|
||||
VALUE "ProductVersion", "1.26.231.0"
|
||||
VALUE "ProductVersion", "1.26.232.0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
|
|
@ -5764,15 +5764,15 @@
|
|||
{
|
||||
"Name" = "8:Microsoft Visual Studio"
|
||||
"ProductName" = "8:oscar64"
|
||||
"ProductCode" = "8:{1252F689-2134-45B0-8AB1-7E99CFD00AD3}"
|
||||
"PackageCode" = "8:{8D92131F-28A4-4D0D-AD05-BA2DE216244D}"
|
||||
"ProductCode" = "8:{BA1EBA7F-3736-4285-BBE0-341377F288CA}"
|
||||
"PackageCode" = "8:{2C585F74-7D65-4560-B715-9916BA763D44}"
|
||||
"UpgradeCode" = "8:{9AB61EFF-ACAC-4079-9950-8D96615CD4EF}"
|
||||
"AspNetVersion" = "8:2.0.50727.0"
|
||||
"RestartWWWService" = "11:FALSE"
|
||||
"RemovePreviousVersions" = "11:TRUE"
|
||||
"DetectNewerInstalledVersion" = "11:TRUE"
|
||||
"InstallAllUsers" = "11:FALSE"
|
||||
"ProductVersion" = "8:1.26.231"
|
||||
"ProductVersion" = "8:1.26.232"
|
||||
"Manufacturer" = "8:oscar64"
|
||||
"ARPHELPTELEPHONE" = "8:"
|
||||
"ARPHELPLINK" = "8:"
|
||||
|
|
Loading…
Reference in New Issue