diff options
author | Paul Gilbert | 2018-11-10 10:34:28 -0800 |
---|---|---|
committer | Paul Gilbert | 2018-12-08 19:05:59 -0800 |
commit | cde50e00edea1c0cc0235aa814501038e6a1792c (patch) | |
tree | b3bcb8fb0057826d7f0364122549389fac0c5446 /engines | |
parent | 62315b969d851166c94c6fb73a3da7ac4ab44a73 (diff) | |
download | scummvm-rg350-cde50e00edea1c0cc0235aa814501038e6a1792c.tar.gz scummvm-rg350-cde50e00edea1c0cc0235aa814501038e6a1792c.tar.bz2 scummvm-rg350-cde50e00edea1c0cc0235aa814501038e6a1792c.zip |
GLK: Fix handling of negative file offsets in MemoryStream::setPosition
Diffstat (limited to 'engines')
-rw-r--r-- | engines/gargoyle/streams.cpp | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/engines/gargoyle/streams.cpp b/engines/gargoyle/streams.cpp index 659fcd00d6..41f3caf1b4 100644 --- a/engines/gargoyle/streams.cpp +++ b/engines/gargoyle/streams.cpp @@ -459,29 +459,31 @@ glui32 MemoryStream::getPosition() const { } void MemoryStream::setPosition(glui32 pos, glui32 seekMode) { + glsi32 newPos = pos; + if (!_unicode) { if (seekMode == seekmode_Current) - pos = ((unsigned char *)_bufPtr - (unsigned char *)_buf) + pos; + newPos = ((unsigned char *)_bufPtr - (unsigned char *)_buf) + newPos; else if (seekMode == seekmode_End) - pos = ((unsigned char *)_bufEof - (unsigned char *)_buf) + pos; + newPos = ((unsigned char *)_bufEof - (unsigned char *)_buf) + newPos; else - /* pos = pos */; - if (pos < 0) - pos = 0; - if (pos > (glui32)((unsigned char *)_bufEof - (unsigned char *)_buf)) - pos = ((unsigned char *)_bufEof - (unsigned char *)_buf); - _bufPtr = (unsigned char *)_buf + pos; + /* newPos = newPos */; + if (newPos < 0) + newPos = 0; + if (newPos > ((unsigned char *)_bufEof - (unsigned char *)_buf)) + newPos = ((unsigned char *)_bufEof - (unsigned char *)_buf); + _bufPtr = (unsigned char *)_buf + newPos; } else { if (seekMode == seekmode_Current) - pos = ((glui32 *)_bufPtr - (glui32 *)_buf) + pos; + newPos = ((glui32 *)_bufPtr - (glui32 *)_buf) + newPos; else if (seekMode == seekmode_End) - pos = ((glui32 *)_bufEof - (glui32 *)_buf) + pos; + newPos = ((glui32 *)_bufEof - (glui32 *)_buf) + newPos; - if (pos < 0) - pos = 0; - if (pos > (glui32)((glui32 *)_bufEof - (glui32 *)_buf)) - pos = ((glui32 *)_bufEof - (glui32 *)_buf); - _bufPtr = (glui32 *)_buf + pos; + if (newPos < 0) + newPos = 0; + if (newPos > ((glui32 *)_bufEof - (glui32 *)_buf)) + newPos = ((glui32 *)_bufEof - (glui32 *)_buf); + _bufPtr = (glui32 *)_buf + newPos; } } |