diff --git a/plugins/libimhex/source/pattern_language/evaluator.cpp b/plugins/libimhex/source/pattern_language/evaluator.cpp index f65dcc90f..29522c42e 100644 --- a/plugins/libimhex/source/pattern_language/evaluator.cpp +++ b/plugins/libimhex/source/pattern_language/evaluator.cpp @@ -1021,7 +1021,7 @@ namespace hex::pl { PatternData* Evaluator::evaluateStaticArray(ASTNodeArrayVariableDecl *node) { std::optional color; - size_t arraySize = 0; + ssize_t arraySize = 0; auto startOffset = this->m_currOffset; PatternData *templatePattern; @@ -1076,6 +1076,9 @@ namespace hex::pl { } } + if (arraySize < 0) + this->getConsole().abortEvaluation("array size cannot be negative"); + if (auto typeDecl = dynamic_cast(node->getType()); typeDecl != nullptr) { if (auto builtinType = dynamic_cast(typeDecl->getType()); builtinType != nullptr) { if (builtinType->getType() == Token::ValueType::Padding) @@ -1143,9 +1146,12 @@ namespace hex::pl { using Type = std::remove_cvref_t; if constexpr (std::is_floating_point_v) this->getConsole().abortEvaluation("bitfield entry size must be an integer value"); - return static_cast(value); + return static_cast(value); }, valueNode->getValue()); + if (arraySize < 0) + this->getConsole().abortEvaluation("array size cannot be negative"); + for (u64 i = 0; i < arraySize; i++) { addEntry(i); }