diff --git a/src/fileio.cpp b/src/fileio.cpp index e17eaf654a..851090c071 100644 --- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -254,7 +254,8 @@ void FioOpenFile(int slot, const char *filename, Subdirectory subdir) #endif /* LIMITED_FDS */ f = FioFOpenFile(filename, "rb", subdir); if (f == NULL) usererror("Cannot open file '%s'", filename); - uint32 pos = ftell(f); + long pos = ftell(f); + if (pos < 0) usererror("Cannot read file '%s'", filename); FioCloseFile(slot); // if file was opened before, close it _fio.handles[slot] = f; @@ -271,7 +272,7 @@ void FioOpenFile(int slot, const char *filename, Subdirectory subdir) _fio.usage_count[slot] = 0; _fio.open_handles++; #endif /* LIMITED_FDS */ - FioSeekToFile(slot, pos); + FioSeekToFile(slot, (uint32)pos); } static const char * const _subdirs[] = { diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp index bbd670a71c..df86850302 100644 --- a/src/newgrf_config.cpp +++ b/src/newgrf_config.cpp @@ -360,10 +360,10 @@ static bool CalcGRFMD5Sum(GRFConfig *config, Subdirectory subdir) f = FioFOpenFile(config->filename, "rb", subdir, &size); if (f == NULL) return false; - size_t start = ftell(f); + long start = ftell(f); size = min(size, GRFGetSizeOfDataSection(f)); - if (fseek(f, start, SEEK_SET) < 0) { + if (start < 0 || fseek(f, start, SEEK_SET) < 0) { FioFCloseFile(f); return false; } diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp index 8e53ade6ff..85a1236264 100644 --- a/src/smallmap_gui.cpp +++ b/src/smallmap_gui.cpp @@ -1418,10 +1418,12 @@ int SmallMapWindow::GetPositionOnLegend(Point pt) case WID_SM_LEGEND: // Legend if (this->map_type == SMT_INDUSTRY || this->map_type == SMT_LINKSTATS || this->map_type == SMT_OWNER) { int click_pos = this->GetPositionOnLegend(pt); + if (click_pos < 0) break; + /* If industry type small map*/ if (this->map_type == SMT_INDUSTRY) { /* If click on industries label, find right industry type and enable/disable it. */ - if (click_pos >= 0 && click_pos < _smallmap_industry_count) { + if (click_pos < _smallmap_industry_count) { this->SelectLegendItem(click_pos, _legend_from_industries, _smallmap_industry_count); } } else if (this->map_type == SMT_LINKSTATS) {