aboutsummaryrefslogtreecommitdiff
path: root/engines/cge2/fileio.cpp
diff options
context:
space:
mode:
authorStrangerke2014-09-26 23:41:31 +0200
committerStrangerke2014-09-26 23:41:31 +0200
commitb5ad4eedb3cb011eb6a03a131b9ef7cd1afd47cd (patch)
treea37e45edf065e190192cc9bb067724fe5b0af214 /engines/cge2/fileio.cpp
parentd7e83d34277d43c1ca24203911158b4dbf686e7b (diff)
downloadscummvm-rg350-b5ad4eedb3cb011eb6a03a131b9ef7cd1afd47cd.tar.gz
scummvm-rg350-b5ad4eedb3cb011eb6a03a131b9ef7cd1afd47cd.tar.bz2
scummvm-rg350-b5ad4eedb3cb011eb6a03a131b9ef7cd1afd47cd.zip
CGE2: Fix a crash when detecting an empty set of VOL files
Diffstat (limited to 'engines/cge2/fileio.cpp')
-rw-r--r--engines/cge2/fileio.cpp14
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) {