aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorWillem Jan Palenstijn2011-08-22 10:21:03 +0200
committerWillem Jan Palenstijn2011-08-22 10:24:26 +0200
commit48dd74dd6d2c5514eba475f3612a0a1333342763 (patch)
treec8957f488f838f13b6c46c13b26dab65488d2db3 /engines
parent63e0878a55706bc68cc75c4cc8f62c8c7952ff69 (diff)
downloadscummvm-rg350-48dd74dd6d2c5514eba475f3612a0a1333342763.tar.gz
scummvm-rg350-48dd74dd6d2c5514eba475f3612a0a1333342763.tar.bz2
scummvm-rg350-48dd74dd6d2c5514eba475f3612a0a1333342763.zip
SCUMM: Revert "Avoid calling malloc with new_size=0"
This reverts commit d6f7e5933657e2e6fcbd1accf9f8a4b77454daec, and marks the issue with a FIXME. The problem is that it not only skips the malloc, but also the other code in that block.
Diffstat (limited to 'engines')
-rw-r--r--engines/scumm/smush/channel.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/engines/scumm/smush/channel.cpp b/engines/scumm/smush/channel.cpp
index f5e0747ba8..fd822f56b6 100644
--- a/engines/scumm/smush/channel.cpp
+++ b/engines/scumm/smush/channel.cpp
@@ -60,6 +60,8 @@ void SmushChannel::processBuffer() {
if (offset < _tbufferSize) {
int new_size = _tbufferSize - offset;
_tbuffer = (byte *)malloc(new_size);
+ // FIXME: _tbuffer might be 0 if new_size is 0.
+ // NB: Also check other "if (_tbuffer)" locations in smush
if (!_tbuffer)
error("smush channel failed to allocate memory");
memcpy(_tbuffer, _sbuffer + offset, new_size);
@@ -94,16 +96,16 @@ void SmushChannel::processBuffer() {
_tbufferSize = 0;
} else {
if (offset) {
+ byte *old = _tbuffer;
int32 new_size = _tbufferSize - offset;
- if (new_size) {
- byte *old = _tbuffer;
- _tbuffer = (byte *)malloc(new_size);
- if (!_tbuffer)
- error("smush channel failed to allocate memory");
- memcpy(_tbuffer, old + offset, new_size);
- _tbufferSize = new_size;
- free(old);
- }
+ _tbuffer = (byte *)malloc(new_size);
+ // FIXME: _tbuffer might be 0 if new_size is 0.
+ // NB: Also check other "if (_tbuffer)" locations in smush
+ if (!_tbuffer)
+ error("smush channel failed to allocate memory");
+ memcpy(_tbuffer, old + offset, new_size);
+ _tbufferSize = new_size;
+ free(old);
}
}
}