summaryrefslogtreecommitdiff
path: root/src/bmp.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2013-11-23 13:15:07 +0000
committerrubidium <rubidium@openttd.org>2013-11-23 13:15:07 +0000
commit0e9c9921040a1d0e2aa4b820b20535f40a0d75a3 (patch)
tree6dd17568acbfb75610e9b4e248436426ead79e89 /src/bmp.cpp
parentb3e93d65208f74802595b12e682d98a4d534a328 (diff)
downloadopenttd-0e9c9921040a1d0e2aa4b820b20535f40a0d75a3.tar.xz
(svn r26058) -Fix: handle the return value of a number of functions better
Diffstat (limited to 'src/bmp.cpp')
-rw-r--r--src/bmp.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/bmp.cpp b/src/bmp.cpp
index a93785d4f..2cb3dbf78 100644
--- a/src/bmp.cpp
+++ b/src/bmp.cpp
@@ -25,18 +25,24 @@ void BmpInitializeBuffer(BmpBuffer *buffer, FILE *file)
static inline void AdvanceBuffer(BmpBuffer *buffer)
{
+ if (buffer->read < 0) return;
+
buffer->read = (int)fread(buffer->data, 1, BMP_BUFFER_SIZE, buffer->file);
buffer->pos = 0;
}
static inline bool EndOfBuffer(BmpBuffer *buffer)
{
+ if (buffer->read < 0) return false;
+
if (buffer->pos == buffer->read || buffer->pos < 0) AdvanceBuffer(buffer);
return buffer->pos == buffer->read;
}
static inline byte ReadByte(BmpBuffer *buffer)
{
+ if (buffer->read < 0) return 0;
+
if (buffer->pos == buffer->read || buffer->pos < 0) AdvanceBuffer(buffer);
buffer->real_pos++;
return buffer->data[buffer->pos++];
@@ -62,7 +68,9 @@ static inline void SkipBytes(BmpBuffer *buffer, int bytes)
static inline void SetStreamOffset(BmpBuffer *buffer, int offset)
{
- fseek(buffer->file, offset, SEEK_SET);
+ if (fseek(buffer->file, offset, SEEK_SET) < 0) {
+ buffer->read = -1;
+ }
buffer->pos = -1;
buffer->real_pos = offset;
AdvanceBuffer(buffer);