diff options
| author | 2019-07-29 20:35:52 +0000 | |
|---|---|---|
| committer | 2019-07-29 20:35:52 +0000 | |
| commit | 1a902d383eef1e042d4462cd07b9384fcdf4d118 (patch) | |
| tree | 766b8ab720fa5da11730d2fc2388f51b9d14de49 /node/rerolldicenode.cpp | |
| parent | f5906125576a8323a731c9456ce3dfc53b67ef59 (diff) | |
| parent | 0d4b68221bda594cc695d216dfa21306ddb69c85 (diff) | |
| download | OneRoll-1a902d383eef1e042d4462cd07b9384fcdf4d118.tar.gz OneRoll-1a902d383eef1e042d4462cd07b9384fcdf4d118.zip | |
Merge branch 'liberation' into 'master'
Add fuzzer on the DiceParser
See merge request kde/rolisteam-diceparser!2
Diffstat (limited to 'node/rerolldicenode.cpp')
| -rw-r--r-- | node/rerolldicenode.cpp | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/node/rerolldicenode.cpp b/node/rerolldicenode.cpp index 56ee6d9..70475a5 100644 --- a/node/rerolldicenode.cpp +++ b/node/rerolldicenode.cpp @@ -1,5 +1,6 @@ #include "rerolldicenode.h" #include "parsingtoolbox.h" +#include <utility> RerollDiceNode::RerollDiceNode(bool reroll, bool addingMode) : m_diceResult(new DiceResult()), m_validator(nullptr), m_reroll(reroll), m_adding(addingMode) @@ -26,7 +27,6 @@ void RerollDiceNode::run(ExecutionNode* previous) for(auto& die : previous_result->getResultList()) { Die* tmpdie= new Die(*die); - //*tmpdie= *die; m_diceResult->insertResult(tmpdie); die->displayed(); } @@ -35,10 +35,22 @@ void RerollDiceNode::run(ExecutionNode* previous) QList<Die*>& list= m_diceResult->getResultList(); QList<Die*> toRemove; - for(int i= 0; i < list.size(); ++i) + for(auto& die : list) { - auto die= list.at(i); bool finished= false; + auto state + = m_validator->isValidRangeSize(std::make_pair<qint64, qint64>(die->getBase(), die->getMaxValue())); + if((Dice::CONDITION_STATE::ALWAYSTRUE == state && m_adding) + || (!m_reroll && !m_adding && state == Dice::CONDITION_STATE::UNREACHABLE)) + { + m_errors.insert(Dice::ERROR_CODE::ENDLESS_LOOP_ERROR, + QObject::tr("Condition (%1) cause an endless loop with this dice: %2") + .arg(toString(true)) + .arg(QStringLiteral("d[%1,%2]") + .arg(static_cast<int>(die->getBase())) + .arg(static_cast<int>(die->getMaxValue())))); + continue; + } while(m_validator->hasValid(die, false) && !finished) { if(m_instruction != nullptr) @@ -52,8 +64,8 @@ void RerollDiceNode::run(ExecutionNode* previous) { toRemove.append(die); list.append(lastResult->getResultList()); + lastResult->clear(); } - lastResult->clear(); } } else @@ -79,7 +91,8 @@ void RerollDiceNode::run(ExecutionNode* previous) } else { - m_errors.insert(ExecutionNode::DIE_RESULT_EXPECTED, + m_errors.insert( + Dice::ERROR_CODE::DIE_RESULT_EXPECTED, QObject::tr( " The a operator expects dice result. Please check the documentation and fix your command.")); } |