mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 11:38:21 +02:00
Handle uninitialized CE attribute data
This commit is contained in:
parent
b4cfc119a7
commit
547c9908f5
2 changed files with 20 additions and 8 deletions
|
@ -3847,6 +3847,13 @@ uint8* CeContext::CeMalloc(int size)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8* CeContext::CeMallocZero(int size)
|
||||||
|
{
|
||||||
|
uint8* ptr = CeMalloc(size);
|
||||||
|
memset(ptr, 0, size);
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
bool CeContext::CeFree(addr_ce addr)
|
bool CeContext::CeFree(addr_ce addr)
|
||||||
{
|
{
|
||||||
#ifdef CE_ENABLE_HEAP
|
#ifdef CE_ENABLE_HEAP
|
||||||
|
@ -3892,7 +3899,7 @@ addr_ce CeContext::GetConstantData(BeConstant* constant)
|
||||||
auto result = mCeMachine->WriteConstant(structData, writeConstant, this);
|
auto result = mCeMachine->WriteConstant(structData, writeConstant, this);
|
||||||
BF_ASSERT(result == CeErrorKind_None);
|
BF_ASSERT(result == CeErrorKind_None);
|
||||||
|
|
||||||
uint8* ptr = CeMalloc(structData.mData.mSize);
|
uint8* ptr = CeMallocZero(structData.mData.mSize);
|
||||||
memcpy(ptr, structData.mData.mVals, structData.mData.mSize);
|
memcpy(ptr, structData.mData.mVals, structData.mData.mSize);
|
||||||
return (addr_ce)(ptr - mMemory.mVals);
|
return (addr_ce)(ptr - mMemory.mVals);
|
||||||
}
|
}
|
||||||
|
@ -4123,9 +4130,7 @@ addr_ce CeContext::GetString(int stringId)
|
||||||
int allocSize = stringTypeInst->mInstSize + (int)str.length() + 1;
|
int allocSize = stringTypeInst->mInstSize + (int)str.length() + 1;
|
||||||
int charsOffset = stringTypeInst->mInstSize;
|
int charsOffset = stringTypeInst->mInstSize;
|
||||||
|
|
||||||
uint8* mem = CeMalloc(allocSize);
|
uint8* mem = CeMallocZero(allocSize);
|
||||||
|
|
||||||
memset(mem, 0, allocSize);
|
|
||||||
|
|
||||||
auto lenByteCount = stringTypeInst->mFieldInstances[0].mResolvedType->mSize;
|
auto lenByteCount = stringTypeInst->mFieldInstances[0].mResolvedType->mSize;
|
||||||
auto lenOffset = stringTypeInst->mFieldInstances[0].mDataOffset;
|
auto lenOffset = stringTypeInst->mFieldInstances[0].mDataOffset;
|
||||||
|
@ -4374,7 +4379,7 @@ bool CeContext::WriteConstant(BfModule* module, addr_ce addr, BfConstant* consta
|
||||||
if (type->IsPointer())
|
if (type->IsPointer())
|
||||||
{
|
{
|
||||||
auto elementType = type->GetUnderlyingType();
|
auto elementType = type->GetUnderlyingType();
|
||||||
auto toPtr = CeMalloc(elementType->mSize);
|
auto toPtr = CeMallocZero(elementType->mSize);
|
||||||
addr_ce toAddr = (addr_ce)(toPtr - mMemory.mVals);
|
addr_ce toAddr = (addr_ce)(toPtr - mMemory.mVals);
|
||||||
if (ptrSize == 4)
|
if (ptrSize == 4)
|
||||||
CE_GETC(int32) = (int32)toAddr;
|
CE_GETC(int32) = (int32)toAddr;
|
||||||
|
@ -4827,6 +4832,12 @@ BfIRValue CeContext::CreateConstant(BfModule* module, uint8* ptr, BfType* bfType
|
||||||
auto allocSizeOffset = stringTypeInst->mFieldInstances[1].mDataOffset;
|
auto allocSizeOffset = stringTypeInst->mFieldInstances[1].mDataOffset;
|
||||||
auto ptrOffset = stringTypeInst->mFieldInstances[2].mDataOffset;
|
auto ptrOffset = stringTypeInst->mFieldInstances[2].mDataOffset;
|
||||||
|
|
||||||
|
if (addr + ptrOffset + 4 > memSize)
|
||||||
|
{
|
||||||
|
// Memory error
|
||||||
|
return irBuilder->CreateConstNull(irBuilder->MapType(typeInst));
|
||||||
|
}
|
||||||
|
|
||||||
int32 lenVal = *(int32*)(instData + lenOffset);
|
int32 lenVal = *(int32*)(instData + lenOffset);
|
||||||
|
|
||||||
char* charPtr = NULL;
|
char* charPtr = NULL;
|
||||||
|
@ -5088,7 +5099,7 @@ BfIRValue CeContext::CreateAttribute(BfAstNode* targetSrc, BfModule* module, BfI
|
||||||
|
|
||||||
module->mContext->mUnreifiedModule->PopulateType(customAttribute->mType);
|
module->mContext->mUnreifiedModule->PopulateType(customAttribute->mType);
|
||||||
if (ceAttrAddr == 0)
|
if (ceAttrAddr == 0)
|
||||||
ceAttrAddr = CeMalloc(customAttribute->mType->mSize) - mMemory.mVals;
|
ceAttrAddr = CeMallocZero(customAttribute->mType->mSize) - mMemory.mVals;
|
||||||
BfIRValue ceAttrVal = module->mBfIRBuilder->CreateConstAggCE(module->mBfIRBuilder->MapType(customAttribute->mType, BfIRPopulateType_Identity), ceAttrAddr);
|
BfIRValue ceAttrVal = module->mBfIRBuilder->CreateConstAggCE(module->mBfIRBuilder->MapType(customAttribute->mType, BfIRPopulateType_Identity), ceAttrAddr);
|
||||||
BfTypedValue ceAttrTypedValue(ceAttrVal, customAttribute->mType);
|
BfTypedValue ceAttrTypedValue(ceAttrVal, customAttribute->mType);
|
||||||
|
|
||||||
|
|
|
@ -1169,6 +1169,7 @@ public:
|
||||||
void AddTypeSigRebuild(BfType* type);
|
void AddTypeSigRebuild(BfType* type);
|
||||||
void AddFileRebuild(const StringImpl& filePath);
|
void AddFileRebuild(const StringImpl& filePath);
|
||||||
uint8* CeMalloc(int size);
|
uint8* CeMalloc(int size);
|
||||||
|
uint8* CeMallocZero(int size);
|
||||||
bool CeFree(addr_ce addr);
|
bool CeFree(addr_ce addr);
|
||||||
addr_ce CeAllocArray(BfArrayType* arrayType, int count, addr_ce& elemsAddr);
|
addr_ce CeAllocArray(BfArrayType* arrayType, int count, addr_ce& elemsAddr);
|
||||||
addr_ce GetReflectTypeDecl(int typeId);
|
addr_ce GetReflectTypeDecl(int typeId);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue