mirror of https://github.com/OpenTTD/OpenTTD.git
Fix: Protect against a few out of bounds or uninitialised usage errors
This commit is contained in:
parent
52ed3bcbaa
commit
b5028efc1f
|
@ -154,6 +154,7 @@ static uint32 RotateRight(uint32 val, uint32 rot)
|
|||
{
|
||||
/* Do not rotate more than necessary */
|
||||
rot %= 32;
|
||||
assert(rot > 0);
|
||||
|
||||
return (val >> rot) | (val << (32 - rot));
|
||||
}
|
||||
|
|
|
@ -145,6 +145,7 @@ static uint FindShipTrack(const Ship *v, TileIndex tile, DiagDirection dir, Trac
|
|||
|
||||
Track best_track = INVALID_TRACK;
|
||||
|
||||
assert(bits != TRACK_BIT_NONE);
|
||||
do {
|
||||
Track i = RemoveFirstTrack(&bits);
|
||||
|
||||
|
@ -176,7 +177,7 @@ good:;
|
|||
best_length = pfs.best_length;
|
||||
bad:;
|
||||
|
||||
} while (bits != 0);
|
||||
} while (bits != TRACK_BIT_NONE);
|
||||
|
||||
*track = best_track;
|
||||
return best_bird_dist;
|
||||
|
|
|
@ -28,6 +28,8 @@ template <typename Tpf> void DumpState(Tpf &pf1, Tpf &pf2)
|
|||
pf2.DumpBase(dmp2);
|
||||
FILE *f1 = fopen("yapf1.txt", "wt");
|
||||
FILE *f2 = fopen("yapf2.txt", "wt");
|
||||
assert(f1 != NULL);
|
||||
assert(f2 != NULL);
|
||||
fwrite(dmp1.m_out.Data(), 1, dmp1.m_out.Size(), f1);
|
||||
fwrite(dmp2.m_out.Data(), 1, dmp2.m_out.Size(), f2);
|
||||
fclose(f1);
|
||||
|
|
|
@ -449,6 +449,7 @@ enum Roadside {
|
|||
ROADSIDE_GRASS = 1, ///< Road on grass
|
||||
ROADSIDE_PAVED = 2, ///< Road with paved sidewalks
|
||||
ROADSIDE_STREET_LIGHTS = 3, ///< Road with street lights on paved sidewalks
|
||||
// 4 is unused for historical reasons
|
||||
ROADSIDE_TREES = 5, ///< Road with trees on paved sidewalks
|
||||
ROADSIDE_GRASS_ROAD_WORKS = 6, ///< Road on grass with road works
|
||||
ROADSIDE_PAVED_ROAD_WORKS = 7, ///< Road with sidewalks and road works
|
||||
|
|
|
@ -371,7 +371,10 @@ static bool CompareFiles(const char *n1, const char *n2)
|
|||
if (f2 == NULL) return false;
|
||||
|
||||
FILE *f1 = fopen(n1, "rb");
|
||||
if (f1 == NULL) error("can't open %s", n1);
|
||||
if (f1 == NULL) {
|
||||
fclose(f2);
|
||||
error("can't open %s", n1);
|
||||
}
|
||||
|
||||
size_t l1, l2;
|
||||
do {
|
||||
|
|
|
@ -215,7 +215,10 @@ bool CompareFiles(const char *n1, const char *n2)
|
|||
if (f2 == NULL) return false;
|
||||
|
||||
FILE *f1 = fopen(n1, "rb");
|
||||
if (f1 == NULL) error("can't open %s", n1);
|
||||
if (f1 == NULL) {
|
||||
fclose(f2);
|
||||
error("can't open %s", n1);
|
||||
}
|
||||
|
||||
size_t l1, l2;
|
||||
do {
|
||||
|
|
|
@ -719,7 +719,7 @@ void UpdateTownCargoTotal(Town *t)
|
|||
static void UpdateTownCargoes(Town *t, TileIndex start, bool update_total = true)
|
||||
{
|
||||
CargoArray accepted, produced;
|
||||
CargoTypes dummy;
|
||||
CargoTypes dummy = 0;
|
||||
|
||||
/* Gather acceptance for all houses in an area around the start tile.
|
||||
* The area is composed of the square the tile is in, extended one square in all
|
||||
|
|
|
@ -61,7 +61,7 @@ static inline bool IsValidTrackdirForRoadVehicle(Trackdir trackdir)
|
|||
*/
|
||||
static inline bool IsValidTrackdir(Trackdir trackdir)
|
||||
{
|
||||
return (1 << trackdir & TRACKDIR_BIT_MASK) != TRACKDIR_BIT_NONE;
|
||||
return trackdir != INVALID_TRACKDIR && ((1 << trackdir & TRACKDIR_BIT_MASK) != TRACKDIR_BIT_NONE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -938,6 +938,8 @@ static void DrawOverlappedWindow(Window *w, int left, int top, int right, int bo
|
|||
void DrawOverlappedWindowForAll(int left, int top, int right, int bottom)
|
||||
{
|
||||
Window *w;
|
||||
|
||||
DrawPixelInfo *old_dpi = _cur_dpi;
|
||||
DrawPixelInfo bk;
|
||||
_cur_dpi = &bk;
|
||||
|
||||
|
@ -951,6 +953,7 @@ void DrawOverlappedWindowForAll(int left, int top, int right, int bottom)
|
|||
DrawOverlappedWindow(w, max(left, w->left), max(top, w->top), min(right, w->left + w->width), min(bottom, w->top + w->height));
|
||||
}
|
||||
}
|
||||
_cur_dpi = old_dpi;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue