summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/control.cc5
-rw-r--r--src/value.h10
2 files changed, 12 insertions, 3 deletions
diff --git a/src/control.cc b/src/control.cc
index db12f71..c50402f 100644
--- a/src/control.cc
+++ b/src/control.cc
@@ -79,7 +79,7 @@ void ControlModule::for_eval(AbstractNode &node, const ModuleInstantiation &inst
if (it_values.type() == Value::RANGE) {
Value::RangeType range = it_values.toRange();
range.normalize();
- if ((range.step > 0) && (range.begin-range.end)/range.step < 10000) {
+ if (range.nbsteps()<10000) {
for (double i = range.begin; i <= range.end; i += range.step) {
c.set_variable(it_name, Value(i));
for_eval(node, inst, l+1, &c, evalctx);
@@ -147,6 +147,7 @@ AbstractNode* ControlModule::getChild(const Value& value, const EvalContext* mod
// (e.g. first child of difference is invalid)
PRINTB("WARNING: Children index (%d) out of bounds (%d children)"
, n % modulectx->numChildren());
+ return NULL;
}
// OK
return modulectx->getChild(n)->evaluate(modulectx);
@@ -226,7 +227,7 @@ AbstractNode *ControlModule::instantiate(const Context* /*ctx*/, const ModuleIns
AbstractNode* node = new AbstractNode(inst);
Value::RangeType range = value.toRange();
range.normalize();
- if ((range.step>0) && ((range.begin-range.end)/range.step>=10000)) {
+ if (range.nbsteps()>=10000) {
PRINTB("WARNING: Bad range parameter for children: too many elements (%d).", (int)((range.begin-range.end)/range.step));
return NULL;
}
diff --git a/src/value.h b/src/value.h
index 4d8346f..388b721 100644
--- a/src/value.h
+++ b/src/value.h
@@ -4,6 +4,7 @@
#include <vector>
#include <string>
#include <algorithm>
+#include <limits>
// Workaround for https://bugreports.qt-project.org/browse/QTBUG-22829
#ifndef Q_MOC_RUN
@@ -42,10 +43,17 @@ public:
/// inverse begin/end if begin is upper than end
void normalize() {
- if (end < begin) {
+ if ((step>0) && (end < begin)) {
std::swap(begin,end);
}
}
+ /// return number of steps, max int value if step is null
+ int nbsteps() const {
+ if (step<=0) {
+ return std::numeric_limits<int>::max();
+ }
+ return (int)((begin-end)/step);
+ }
double begin;
double step;
contact: Jan Huwald // Impressum