From 13fd2cd335f1162758348ae3e2e9c2a1a4cc5602 Mon Sep 17 00:00:00 2001 From: rubidium Date: Fri, 11 Feb 2011 09:33:38 +0000 Subject: [PATCH] (svn r22057) -Fix: waypoint conversion could (previously) silently overfill the pool and crash --- src/saveload/station_sl.cpp | 3 +++ src/saveload/waypoint_sl.cpp | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/saveload/station_sl.cpp b/src/saveload/station_sl.cpp index 3304250248..e41cb32888 100644 --- a/src/saveload/station_sl.cpp +++ b/src/saveload/station_sl.cpp @@ -75,6 +75,9 @@ void MoveBuoysToWaypoints() /* Delete the station, so we can make it a real waypoint. */ delete st; + /* Stations and waypoints are in the same pool, so if a station + * is deleted there must be place for a Waypoint. */ + assert(Waypoint::CanAllocateItem()); Waypoint *wp = new (index) Waypoint(xy); wp->town = town; wp->string_id = train ? STR_SV_STNAME_WAYPOINT : STR_SV_STNAME_BUOY; diff --git a/src/saveload/waypoint_sl.cpp b/src/saveload/waypoint_sl.cpp index 3dce9e3d55..9d1f164b47 100644 --- a/src/saveload/waypoint_sl.cpp +++ b/src/saveload/waypoint_sl.cpp @@ -93,6 +93,8 @@ void MoveWaypointsToBaseStations() } } + if (!Waypoint::CanAllocateItem(_old_waypoints.Length())) SlError(STR_ERROR_TOO_MANY_STATIONS_LOADING); + /* All saveload conversions have been done. Create the new waypoints! */ for (OldWaypoint *wp = _old_waypoints.Begin(); wp != _old_waypoints.End(); wp++) { Waypoint *new_wp = new Waypoint(wp->xy);