From 4655bb74f9d6d7f6db8fca9e22721e6c0e1ada12 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 22 Feb 2015 01:52:44 +0200 Subject: [PATCH] Don't go past end of allocation when checking blocks for a signal --- source/libr2c2/signal.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/source/libr2c2/signal.cpp b/source/libr2c2/signal.cpp index 7aa9994..02a07d7 100644 --- a/source/libr2c2/signal.cpp +++ b/source/libr2c2/signal.cpp @@ -107,12 +107,16 @@ void Signal::tick(const Time::TimeDelta &) if(check_allocated_blocks) { unsigned n_blocks = 0; - BlockIter iter = block.next(); - while(iter && iter->get_train()==train) + const Block *last = train->get_block_allocator().last().block(); + if(block.block()!=last) { - if(iter->get_sensor_address()) - ++n_blocks; - iter = iter.next(); + BlockIter iter = block.next(); + while(iter && iter->get_train()==train && iter.block()!=last) + { + if(iter->get_sensor_address()) + ++n_blocks; + iter = iter.next(); + } } check_allocated_blocks = false; -- 2.45.2