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