From b5028efc1fa862073c908c435f84098ccd246fdc Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Sun, 14 Oct 2018 23:36:14 +0100 Subject: Fix: Protect against a few out of bounds or uninitialised usage errors --- src/pathfinder/opf/opf_ship.cpp | 3 ++- src/pathfinder/yapf/yapf_rail.cpp | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'src/pathfinder') diff --git a/src/pathfinder/opf/opf_ship.cpp b/src/pathfinder/opf/opf_ship.cpp index 1a866337c..c993f8203 100644 --- a/src/pathfinder/opf/opf_ship.cpp +++ b/src/pathfinder/opf/opf_ship.cpp @@ -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; diff --git a/src/pathfinder/yapf/yapf_rail.cpp b/src/pathfinder/yapf/yapf_rail.cpp index dccee3686..d3f8e8aee 100644 --- a/src/pathfinder/yapf/yapf_rail.cpp +++ b/src/pathfinder/yapf/yapf_rail.cpp @@ -28,6 +28,8 @@ template 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); -- cgit v1.2.3-70-g09d2