summaryrefslogtreecommitdiff
path: root/src/control.cc
diff options
context:
space:
mode:
authorMarius Kintel <marius@kintel.net>2013-04-10 00:19:29 (GMT)
committerMarius Kintel <marius@kintel.net>2013-04-10 00:19:29 (GMT)
commitfd9dd04f5064a9a21f593670fdcc073fdc14dbfc (patch)
tree0106c3960b636bf9a67ac99faa45f9176c5a5b11 /src/control.cc
parent151593705f0cd83e1c5880607639daae25502d8b (diff)
Print warnings on child index out of bounds
Diffstat (limited to 'src/control.cc')
-rw-r--r--src/control.cc22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/control.cc b/src/control.cc
index 9133f28..446e47e 100644
--- a/src/control.cc
+++ b/src/control.cc
@@ -92,12 +92,15 @@ AbstractNode *ControlModule::evaluate(const Context *ctx, const ModuleInstantiat
if (type == CHILD)
{
- size_t n = 0;
+ int n = 0;
if (evalctx->eval_arguments.size() > 0) {
double v;
if (evalctx->eval_arguments[0].second.getDouble(v)) {
- if (v < 0) return NULL; // Disallow negative child indices
n = trunc(v);
+ if (n < 0) {
+ PRINTB("WARNING: Negative child index (%d) not allowed", n);
+ return NULL; // Disallow negative child indices
+ }
}
}
@@ -107,8 +110,19 @@ AbstractNode *ControlModule::evaluate(const Context *ctx, const ModuleInstantiat
while (tmpc->parent) {
const ModuleContext *filectx = dynamic_cast<const ModuleContext*>(tmpc->parent);
if (filectx) {
- if (filectx->evalctx && n < filectx->evalctx->children.size()) {
- node = filectx->evalctx->children[n]->evaluate_instance(filectx->evalctx);
+ // This will trigger if trying to invoke child from the root of any file
+ // assert(filectx->evalctx);
+
+ if (filectx->evalctx) {
+ if (n < filectx->evalctx->children.size()) {
+ node = filectx->evalctx->children[n]->evaluate_instance(filectx->evalctx);
+ }
+ else {
+ // How to deal with negative objects in this case?
+ // (e.g. first child of difference is invalid)
+ PRINTB("WARNING: Child index (%d) out of bounds (%d children)",
+ n % filectx->evalctx->children.size());
+ }
}
return node;
}
contact: Jan Huwald // Impressum