The International Simutrans Forum

Development => Patches & Projects => Incorporated Patches and Solved Bug Reports => Topic started by: neroden on May 27, 2024, 06:13:16 PM

Title: I believe I found a fencepost error
Post by: neroden on May 27, 2024, 06:13:16 PM
Ran into this while doing other work.  Looks like a fencepost error (off by one).  Indexes can range from 0 to get_count() - 1 last I checked.

diff --git a/src/simutrans/simconvoi.cc b/src/simutrans/simconvoi.cc
index 4e6189ef0..a7656bde8 100644
--- a/src/simutrans/simconvoi.cc
+++ b/src/simutrans/simconvoi.cc
@@ -476,8 +476,8 @@ DBG_MESSAGE("convoi_t::finish_rd()","next_stop_index=%d", next_stop_index );
else {
// since start may have been changed
route_t::index_t start_index = max(1,fahr[vehicle_count-1]->get_route_index())-1;
- if (start_index > route.get_count()) {
- dbg->error( "convoi_t::finish_rd()", "Routeindex of last vehicle of (%s) too large (%hu > %hu)!", get_name(), start_index, route.get_count() );
+ if (start_index >= route.get_count()) {
+ dbg->error( "convoi_t::finish_rd()", "Routeindex of last vehicle of (%s) too large (%hu >= %hu)!", get_name(), start_index, route.get_count() );
start_index = 0;
}
Title: Re: I believe I found a fencepost error
Post by: prissi on June 24, 2024, 07:36:56 AM
Indeed, although that should have never been triggered unless very very old games. Incorporated in r11308