(svn r26061) -Fix: negative result of ftell wasn't handled correctly in some cases

pull/155/head
rubidium 11 years ago
parent 5e0ea95267
commit e4b208c069

@ -254,7 +254,8 @@ void FioOpenFile(int slot, const char *filename, Subdirectory subdir)
#endif /* LIMITED_FDS */ #endif /* LIMITED_FDS */
f = FioFOpenFile(filename, "rb", subdir); f = FioFOpenFile(filename, "rb", subdir);
if (f == NULL) usererror("Cannot open file '%s'", filename); 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 FioCloseFile(slot); // if file was opened before, close it
_fio.handles[slot] = f; _fio.handles[slot] = f;
@ -271,7 +272,7 @@ void FioOpenFile(int slot, const char *filename, Subdirectory subdir)
_fio.usage_count[slot] = 0; _fio.usage_count[slot] = 0;
_fio.open_handles++; _fio.open_handles++;
#endif /* LIMITED_FDS */ #endif /* LIMITED_FDS */
FioSeekToFile(slot, pos); FioSeekToFile(slot, (uint32)pos);
} }
static const char * const _subdirs[] = { static const char * const _subdirs[] = {

@ -360,10 +360,10 @@ static bool CalcGRFMD5Sum(GRFConfig *config, Subdirectory subdir)
f = FioFOpenFile(config->filename, "rb", subdir, &size); f = FioFOpenFile(config->filename, "rb", subdir, &size);
if (f == NULL) return false; if (f == NULL) return false;
size_t start = ftell(f); long start = ftell(f);
size = min(size, GRFGetSizeOfDataSection(f)); size = min(size, GRFGetSizeOfDataSection(f));
if (fseek(f, start, SEEK_SET) < 0) { if (start < 0 || fseek(f, start, SEEK_SET) < 0) {
FioFCloseFile(f); FioFCloseFile(f);
return false; return false;
} }

@ -1418,10 +1418,12 @@ int SmallMapWindow::GetPositionOnLegend(Point pt)
case WID_SM_LEGEND: // Legend case WID_SM_LEGEND: // Legend
if (this->map_type == SMT_INDUSTRY || this->map_type == SMT_LINKSTATS || this->map_type == SMT_OWNER) { if (this->map_type == SMT_INDUSTRY || this->map_type == SMT_LINKSTATS || this->map_type == SMT_OWNER) {
int click_pos = this->GetPositionOnLegend(pt); int click_pos = this->GetPositionOnLegend(pt);
if (click_pos < 0) break;
/* If industry type small map*/ /* If industry type small map*/
if (this->map_type == SMT_INDUSTRY) { if (this->map_type == SMT_INDUSTRY) {
/* If click on industries label, find right industry type and enable/disable it. */ /* 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); this->SelectLegendItem(click_pos, _legend_from_industries, _smallmap_industry_count);
} }
} else if (this->map_type == SMT_LINKSTATS) { } else if (this->map_type == SMT_LINKSTATS) {

Loading…
Cancel
Save