Skip to content

Commit d061314

Browse files
committed
evaluator: Fix crash when using non-existent variable as section id
1 parent f97999d commit d061314

4 files changed

Lines changed: 12 additions & 3 deletions

File tree

lib/source/pl/core/ast/ast_node_array_variable_decl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ namespace pl::core::ast {
5252
if (this->m_placementSection != nullptr) {
5353
const auto node = this->m_placementSection->evaluate(evaluator);
5454
const auto id = dynamic_cast<ASTNodeLiteral *>(node.get());
55-
if (id == nullptr)
55+
if (id == nullptr) {
56+
scopeGuard.release();
5657
err::E0010.throwError("Cannot use void expression as section identifier.", {}, this->getLocation());
58+
}
5759

5860
evaluator->pushSectionId(u64(id->getValue().toUnsigned()));
5961
} else {

lib/source/pl/core/ast/ast_node_pointer_variable_decl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ namespace pl::core::ast {
3636
if (this->m_placementSection != nullptr) {
3737
const auto node = this->m_placementSection->evaluate(evaluator);
3838
const auto id = dynamic_cast<ASTNodeLiteral *>(node.get());
39-
if (id == nullptr)
39+
if (id == nullptr) {
40+
scopeGuard.release();
4041
err::E0010.throwError("Cannot use void expression as section identifier.", {}, this->getLocation());
42+
}
4143

4244
evaluator->pushSectionId(u64(id->getValue().toUnsigned()));
4345
} else {

lib/source/pl/core/ast/ast_node_variable_decl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ namespace pl::core::ast {
3737
if (this->m_placementSection != nullptr) {
3838
const auto node = this->m_placementSection->evaluate(evaluator);
3939
const auto id = dynamic_cast<ASTNodeLiteral *>(node.get());
40-
if (id == nullptr)
40+
if (id == nullptr) {
41+
scopeGuard.release();
4142
err::E0002.throwError("Cannot use void expression as section identifier.", {}, this->getLocation());
43+
}
4244

4345
evaluator->pushSectionId((u64)id->getValue().toUnsigned());
4446
} else {

lib/source/pl/core/evaluator.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,9 @@ namespace pl::core {
937937
}
938938

939939
void Evaluator::popSectionId() {
940+
if (this->m_sectionIdStack.empty())
941+
return;
942+
940943
this->m_sectionIdStack.pop_back();
941944
}
942945

0 commit comments

Comments
 (0)