From: <Mee...@us...> - 2010-02-13 22:15:44
|
Revision: 3530 http://sc2.svn.sourceforge.net/sc2/?rev=3530&view=rev Author: Meep-Eep Date: 2010-02-13 22:15:38 +0000 (Sat, 13 Feb 2010) Log Message: ----------- Fix bounds checking errors relating to the fuel reserve aboard the flagship. Modified Paths: -------------- trunk/sc2/src/uqm/outfit.c trunk/sc2/src/uqm/sis.c Modified: trunk/sc2/src/uqm/outfit.c =================================================================== --- trunk/sc2/src/uqm/outfit.c 2010-02-12 00:20:25 UTC (rev 3529) +++ trunk/sc2/src/uqm/outfit.c 2010-02-13 22:15:38 UTC (rev 3530) @@ -102,7 +102,8 @@ DWORD FuelVolume; RECT r; - if ((FuelVolume = GLOBAL_SIS (FuelOnBoard)) <= FUEL_RESERVE) + FuelVolume = GLOBAL_SIS (FuelOnBoard); + if (FuelVolume <= FUEL_RESERVE) return; GLOBAL_SIS (FuelOnBoard) = 0; @@ -559,18 +560,17 @@ LockMutex (GraphicsLock); SetContext (SpaceContext); if (GetFTankCapacity (&r.corner) > GLOBAL_SIS (FuelOnBoard) - && GLOBAL_SIS (ResUnits) >= - (DWORD)GLOBAL (FuelCost)) + && GLOBAL_SIS (ResUnits) >= (DWORD)GLOBAL (FuelCost)) { - if (GLOBAL_SIS (FuelOnBoard) >= - FUEL_RESERVE - FUEL_TANK_SCALE) + if (GLOBAL_SIS (FuelOnBoard) >= FUEL_RESERVE) { r.extent.width = 3; DrawPoint (&r.corner); r.corner.x += r.extent.width + 1; DrawPoint (&r.corner); r.corner.x -= r.extent.width; - SetContextForeGroundColor (SetContextBackGroundColor (BLACK_COLOR)); + SetContextForeGroundColor ( + SetContextBackGroundColor (BLACK_COLOR)); DrawFilledRectangle (&r); } DeltaSISGauges (0, FUEL_TANK_SCALE, -GLOBAL (FuelCost)); @@ -590,10 +590,9 @@ SetContext (SpaceContext); if (GLOBAL_SIS (FuelOnBoard)) { - DeltaSISGauges (0, -FUEL_TANK_SCALE, - GLOBAL (FuelCost)); - if (GLOBAL_SIS (FuelOnBoard) - % FUEL_VOLUME_PER_ROW == 0) + DeltaSISGauges (0, -FUEL_TANK_SCALE, GLOBAL (FuelCost)); + if (GLOBAL_SIS (FuelOnBoard) % FUEL_VOLUME_PER_ROW == 0 && + GLOBAL_SIS (FuelOnBoard) >= FUEL_RESERVE) { GetFTankCapacity (&r.corner); SetContextForeGroundColor ( Modified: trunk/sc2/src/uqm/sis.c =================================================================== --- trunk/sc2/src/uqm/sis.c 2010-02-12 00:20:25 UTC (rev 3529) +++ trunk/sc2/src/uqm/sis.c 2010-02-13 22:15:38 UTC (rev 3530) @@ -1418,12 +1418,15 @@ // crew pod, where the Nth unit of fuel would be located. // If the unit does not fit, false is returned, and *slotNr and // *compartmentNr are unchanged. +// Pre: unitNr >= FUEL_RESERER static bool GetFuelTankForFuelUnit (DWORD unitNr, COUNT *slotNr, DWORD *compartmentNr) { COUNT slotI; DWORD capacity = FUEL_RESERVE; + assert (unitNr >= FUEL_RESERVE); + slotI = NUM_MODULE_SLOTS; while (slotI--) { BYTE moduleType = GLOBAL_SIS (ModuleSlots[slotI]); @@ -1447,6 +1450,7 @@ DWORD GetFTankCapacity (POINT *ppt) { + DWORD capacity; DWORD fuelAmount; COUNT slotNr; DWORD compartmentNr; @@ -1454,14 +1458,22 @@ DWORD volume; COUNT rowNr; - + static const Color fuelColors[] = FUEL_COLOR_TABLE; + + capacity = GetFuelTankCapacity (); + fuelAmount = GetFuelTotal (); + if (fuelAmount < FUEL_RESERVE) + { + // Fuel is in the SIS reserve, not in a fuel tank. + // *ppt is unchanged + return capacity; + } - fuelAmount = GetFuelTotal (); if (!GetFuelTankForFuelUnit (fuelAmount, &slotNr, &compartmentNr)) { // Fuel does not fit. *ppt is unchanged. - return GetFuelTankCapacity (); + return capacity; } moduleType = GLOBAL_SIS (ModuleSlots[slotNr]); @@ -1475,10 +1487,11 @@ else ppt->y = 30 - rowNr; + assert (rowNr + 1 < (COUNT) (sizeof fuelColors / sizeof fuelColors[0])); SetContextForeGroundColor (fuelColors[rowNr]); SetContextBackGroundColor (fuelColors[rowNr + 1]); - return GetFuelTankCapacity (); + return capacity; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |