From 45e7e61aa969764dc71ab1bbc574655e07a346a4 Mon Sep 17 00:00:00 2001 From: peter1138 Date: Mon, 27 Nov 2006 21:14:19 +0000 Subject: (svn r7268) -Codechange: change rail vehicle cached weight from 16 to 32 bit values to avoid possible overflows. --- train_cmd.c | 4 ++-- vehicle.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/train_cmd.c b/train_cmd.c index 1179c2958..a38c9d02e 100644 --- a/train_cmd.c +++ b/train_cmd.c @@ -48,11 +48,11 @@ static const byte _state_dir_table[4] = { 0x20, 8, 0x10, 4 }; static void TrainCargoChanged(Vehicle* v) { Vehicle *u; - uint16 weight = 0; + uint32 weight = 0; for (u = v; u != NULL; u = u->next) { const RailVehicleInfo *rvi = RailVehInfo(u->engine_type); - uint16 vweight = (_cargoc.weights[u->cargo_type] * u->cargo_count) / 16; + uint32 vweight = (_cargoc.weights[u->cargo_type] * u->cargo_count) / 16; // Vehicle weight is not added for articulated parts. if (!IsArticulatedPart(u)) { diff --git a/vehicle.h b/vehicle.h index 7681b9de9..b4e1a7190 100644 --- a/vehicle.h +++ b/vehicle.h @@ -54,8 +54,8 @@ typedef struct VehicleRail { uint16 cached_total_length; ///< Length of the whole train, valid only for first engine. // cached values, recalculated when the cargo on a train changes (in addition to the conditions above) - uint16 cached_weight; // total weight of the consist. - uint16 cached_veh_weight; // weight of the vehicle. + uint32 cached_weight; // total weight of the consist. + uint32 cached_veh_weight; // weight of the vehicle. /** * Position/type of visual effect. * bit 0 - 3 = position of effect relative to vehicle. (0 = front, 8 = centre, 15 = rear) -- cgit v1.2.3-70-g09d2