1
0
mirror of synced 2024-11-12 02:00:52 +01:00

Fixed crash when array size variable has a value of zero

This commit is contained in:
WerWolv 2020-12-05 10:36:30 +01:00
parent e82b607fa1
commit 6456a68805

View File

@ -159,6 +159,11 @@ namespace hex::lang {
return { nullptr, 0 };
}
if (arraySize.value() == 0) {
this->m_error = { varDeclNode->getLineNumber(), hex::format("Value of '%s' is zero", member->getArraySizeVariable().value().c_str()) };
return { nullptr, 0 };
}
ASTNodeVariableDecl *processedMember = new ASTNodeVariableDecl(member->getLineNumber(), member->getVariableType(), member->getVariableName(), member->getCustomVariableTypeName(), member->getOffset(), arraySize.value());
std::tie(pattern, memberSize) = this->createArrayPattern(processedMember, memberOffset);
@ -220,8 +225,6 @@ namespace hex::lang {
std::pair<PatternData*, size_t> Evaluator::createArrayPattern(ASTNodeVariableDecl *varDeclNode, u64 offset) {
std::vector<PatternData*> entries;
auto arraySizeVariable = varDeclNode->getArraySizeVariable();
size_t arrayOffset = 0;
std::optional<u32> arrayColor;
for (u32 i = 0; i < varDeclNode->getArraySize(); i++) {