summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-05-05 22:35:33 +0000
committerrubidium <rubidium@openttd.org>2008-05-05 22:35:33 +0000
commit50516f2372074c376fe89c6b7bb51b5105803a59 (patch)
tree7d7888c128635a5db3320701d111516be496f40a /src
parent71800aa7c67ede82fa391e9f462017c4a0a1bf9a (diff)
downloadopenttd-50516f2372074c376fe89c6b7bb51b5105803a59.tar.xz
(svn r12963) -Fix (r12960): loading some NewGRFs could cause an infinite loop.
Diffstat (limited to 'src')
-rw-r--r--src/fileio.cpp8
-rw-r--r--src/network/network_client.cpp2
2 files changed, 7 insertions, 3 deletions
diff --git a/src/fileio.cpp b/src/fileio.cpp
index 184d773ec..b28a27a6b 100644
--- a/src/fileio.cpp
+++ b/src/fileio.cpp
@@ -45,7 +45,7 @@ static Fio _fio;
/* Get current position in file */
uint32 FioGetPos()
{
- return _fio.pos + (_fio.buffer - _fio.buffer_start) - FIO_BUFFER_SIZE;
+ return _fio.pos + (_fio.buffer - _fio.buffer_end);
}
const char *FioGetFilename(uint8 slot)
@@ -92,7 +92,11 @@ byte FioReadByte()
{
if (_fio.buffer == _fio.buffer_end) {
_fio.buffer = _fio.buffer_start;
- _fio.pos += fread(_fio.buffer, 1, FIO_BUFFER_SIZE, _fio.cur_fh);
+ size_t size = fread(_fio.buffer, 1, FIO_BUFFER_SIZE, _fio.cur_fh);
+ _fio.pos += size;
+ _fio.buffer_end = _fio.buffer_start + size;
+
+ if (size == 0) return 0;
}
return *_fio.buffer++;
}
diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp
index 7a1492b11..65eb3e31b 100644
--- a/src/network/network_client.cpp
+++ b/src/network/network_client.cpp
@@ -595,7 +595,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP)
if (maptype == MAP_PACKET_NORMAL) {
// We are still receiving data, put it to the file
- if (fwrite(p->buffer + p->pos, 1, p->size - p->pos, file_pointer) != p->size - p->pos) {
+ if (fwrite(p->buffer + p->pos, 1, p->size - p->pos, file_pointer) != (size_t)(p->size - p->pos)) {
_switch_mode_errorstr = STR_NETWORK_ERR_SAVEGAMEERROR;
return NETWORK_RECV_STATUS_SAVEGAME;
}