]> git.tdb.fi Git - r2c2.git/commitdiff
Don't go past end of allocation when checking blocks for a signal
authorMikko Rasa <tdb@tdb.fi>
Sat, 21 Feb 2015 23:52:44 +0000 (01:52 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 21 Feb 2015 23:53:28 +0000 (01:53 +0200)
source/libr2c2/signal.cpp

index 7aa999438055f4fa31fd6d73ee052f556eeab9ef..02a07d76bc9585861b4c7df0a0954f3060772d7c 100644 (file)
@@ -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;