diff options
-rw-r--r-- | engines/cge2/fileio.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/engines/cge2/fileio.cpp b/engines/cge2/fileio.cpp index 6f8009716b..acb5bb870f 100644 --- a/engines/cge2/fileio.cpp +++ b/engines/cge2/fileio.cpp @@ -116,7 +116,10 @@ BtPage *ResourceManager::getPage(int level, uint16 pageId) { if (_buff[level]._pageNo != pageId) { int32 pos = pageId * kBtSize; _buff[level]._pageNo = pageId; - assert(_catFile->size() > pos); + + if (_catFile->size() <= pos) + return nullptr; + // In the original, there was a check verifying if the // purpose was to write a new file. This should only be // to create a new file, thus it was removed. @@ -139,6 +142,9 @@ BtKeypack *ResourceManager::find(const char *key) { uint16 nxt = kBtValRoot; while (!_catFile->eos()) { BtPage *pg = getPage(lev, nxt); + if (!pg) + return nullptr; + // search if (pg->_header._down != kBtValNone) { int i; @@ -170,7 +176,11 @@ BtKeypack *ResourceManager::find(const char *key) { } bool ResourceManager::exist(const char *name) { - return scumm_stricmp(find(name)->_key, name) == 0; + BtKeypack *result = find(name); + if (!result) + return false; + + return scumm_stricmp(result->_key, name) == 0; } uint16 ResourceManager::catRead(byte *buf, uint16 length) { |