summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2012-01-09 22:19:53 +0000
committerrubidium <rubidium@openttd.org>2012-01-09 22:19:53 +0000
commit2728cb21a94c122565de6ccfacd762eaadaefc32 (patch)
treeb8b947ec9cd65b919f70af35bc5b5d66d759be62
parent6c7c02eb14f31402021b7f5f33173a93e99f0ac3 (diff)
downloadopenttd-2728cb21a94c122565de6ccfacd762eaadaefc32.tar.xz
(svn r23781) -Fix [FS#4964]: under certain circumstances, e.g. a single invalid order, trying to determine the next order state could end up in an infinite loop
-rw-r--r--src/train_cmd.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index f2ea70153..b1e823843 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -2416,7 +2416,7 @@ public:
if (skip_first) ++this->index;
- int conditional_depth = 0;
+ int depth = 0;
do {
/* Wrap around. */
@@ -2434,10 +2434,9 @@ public:
this->v->current_order = *order;
return UpdateOrderDest(this->v, order, 0, true);
case OT_CONDITIONAL: {
- if (conditional_depth > this->v->GetNumOrders()) return false;
VehicleOrderID next = ProcessConditionalOrder(order, this->v);
if (next != INVALID_VEH_ORDER_ID) {
- conditional_depth++;
+ depth++;
this->index = next;
/* Don't increment next, so no break here. */
continue;
@@ -2450,7 +2449,8 @@ public:
/* Don't increment inside the while because otherwise conditional
* orders can lead to an infinite loop. */
++this->index;
- } while (this->index != this->v->cur_real_order_index);
+ depth++;
+ } while (this->index != this->v->cur_real_order_index && depth < this->v->GetNumOrders());
return false;
}