From 2728cb21a94c122565de6ccfacd762eaadaefc32 Mon Sep 17 00:00:00 2001 From: rubidium Date: Mon, 9 Jan 2012 22:19:53 +0000 Subject: [PATCH] (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 --- src/train_cmd.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index f2ea701535..b1e8238434 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; }