From f0ba57ea824081dfc120486e35029a8baa15c704 Mon Sep 17 00:00:00 2001 From: bjarni Date: Sat, 1 Jul 2006 10:46:50 +0000 Subject: [PATCH] (svn r5440) -Backport: rev 5428 -Fix: [vehicles] sovled crash when trying to build a vehicle type, that is set to max 0 (spotted by roboman) --- vehicle.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/vehicle.c b/vehicle.c index 99d0a3b71f..9046b8234a 100644 --- a/vehicle.c +++ b/vehicle.c @@ -2025,6 +2025,14 @@ UnitID GetFreeUnitNumber(byte type) default: assert(0); } + if (max == 0) { + /* we can't build any of this kind of vehicle, so we just return 1 instead of looking for a free number + * a max of 0 will cause the following code to write to a NULL pointer + * We know that 1 is bigger than the max allowed vehicle number, so it's the same as returning something, that is too big + */ + return 1; + } + if (max > gmax) { gmax = max; free(cache);