nodes/patterns: Fixed crashes when recursion occurred

This commit is contained in:
WerWolv
2021-03-07 13:20:33 +01:00
parent d4265f16eb
commit 8423f78586
6 changed files with 45 additions and 0 deletions

View File

@@ -2,6 +2,9 @@
#include <hex/data_processor/attribute.hpp>
#include <set>
#include <vector>
namespace hex::dp {
class Node {
@@ -31,10 +34,15 @@ namespace hex::dp {
attribute.getOutputData().reset();
}
void resetProcessedInputs() {
this->m_processedInputs.clear();
}
private:
u32 m_id;
std::string m_unlocalizedName;
std::vector<Attribute> m_attributes;
std::set<u32> m_processedInputs;
prv::Overlay *m_overlay = nullptr;
Attribute* getConnectedInputAttribute(u32 index) {
@@ -49,6 +57,12 @@ namespace hex::dp {
return connectedAttribute.begin()->second;
}
void markInputProcessed(u32 index) {
const auto &[iter, inserted] = this->m_processedInputs.insert(index);
if (!inserted)
throwNodeError("Recursion detected!");
}
protected:
[[noreturn]] void throwNodeError(std::string_view message) {
@@ -64,6 +78,7 @@ namespace hex::dp {
if (attribute->getType() != Attribute::Type::Buffer)
throwNodeError("Tried to read buffer from non-buffer attribute");
markInputProcessed(index);
attribute->getParentNode()->process();
auto &outputData = attribute->getOutputData();
@@ -83,6 +98,7 @@ namespace hex::dp {
if (attribute->getType() != Attribute::Type::Integer)
throwNodeError("Tried to read integer from non-integer attribute");
markInputProcessed(index);
attribute->getParentNode()->process();
auto &outputData = attribute->getOutputData();
@@ -105,6 +121,7 @@ namespace hex::dp {
if (attribute->getType() != Attribute::Type::Float)
throwNodeError("Tried to read float from non-float attribute");
markInputProcessed(index);
attribute->getParentNode()->process();
auto &outputData = attribute->getOutputData();

View File

@@ -24,6 +24,7 @@ namespace hex::lang {
LogConsole& getConsole() { return this->m_console; }
void setDefaultEndian(std::endian endian) { this->m_defaultDataEndian = endian; }
void setRecursionLimit(u32 limit) { this->m_recursionLimit = limit; }
void setProvider(prv::Provider *provider) { this->m_provider = provider; }
[[nodiscard]] std::endian getCurrentEndian() const { return this->m_endianStack.back(); }
@@ -47,6 +48,8 @@ namespace hex::lang {
std::vector<std::vector<PatternData*>*> m_currMembers;
LogConsole m_console;
u32 m_recursionLimit = 16;
u32 m_currRecursionDepth;
ASTNodeIntegerLiteral* evaluateScopeResolution(ASTNodeScopeResolution *node);

View File

@@ -41,6 +41,7 @@ namespace hex::lang {
prv::Provider *m_provider;
std::endian m_defaultEndian;
u32 m_recursionLimit;
std::optional<std::pair<u32, std::string>> m_currError;
};