diff options
author | Strangerke | 2014-09-26 23:41:51 +0200 |
---|---|---|
committer | Strangerke | 2014-09-26 23:41:51 +0200 |
commit | 690c6cc8d49293a295e56eeace9007450e5af14c (patch) | |
tree | 5455e35b33dfac441dc65f00f35165308d65fed1 /engines/cge | |
parent | b5ad4eedb3cb011eb6a03a131b9ef7cd1afd47cd (diff) | |
download | scummvm-rg350-690c6cc8d49293a295e56eeace9007450e5af14c.tar.gz scummvm-rg350-690c6cc8d49293a295e56eeace9007450e5af14c.tar.bz2 scummvm-rg350-690c6cc8d49293a295e56eeace9007450e5af14c.zip |
CGE: Fix a crash when detecting an empty set of VOL files
Diffstat (limited to 'engines/cge')
-rw-r--r-- | engines/cge/detection.cpp | 4 | ||||
-rw-r--r-- | engines/cge/fileio.cpp | 16 |
2 files changed, 15 insertions, 5 deletions
diff --git a/engines/cge/detection.cpp b/engines/cge/detection.cpp index ee67fb839b..da5eb2b1f2 100644 --- a/engines/cge/detection.cpp +++ b/engines/cge/detection.cpp @@ -157,7 +157,7 @@ const ADGameDescription *CGEMetaEngine::fallbackDetect(const FileMap &allFiles, game = detectGameFilebased(allFiles, fslist, CGE::fileBasedFallback, &filesProps); if (!game) - return 0; + return nullptr; SearchMan.clear(); SearchMan.addDirectory(fslist.begin()->getParent().getPath(), fslist.begin()->getParent()); @@ -167,7 +167,7 @@ const ADGameDescription *CGEMetaEngine::fallbackDetect(const FileMap &allFiles, delete resman; if (!result) - return 0; + return nullptr; reportUnknown(fslist.begin()->getParent(), filesProps); return &s_fallbackDesc; diff --git a/engines/cge/fileio.cpp b/engines/cge/fileio.cpp index d910e275eb..8609110782 100644 --- a/engines/cge/fileio.cpp +++ b/engines/cge/fileio.cpp @@ -121,7 +121,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. @@ -146,6 +149,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; @@ -167,13 +173,17 @@ BtKeypack *ResourceManager::find(const char *key) { return &pg->_leaf[i]; } } - return NULL; + return nullptr; } bool ResourceManager::exist(const char *name) { debugC(1, kCGEDebugFile, "ResourceManager::exist(%s)", 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) { |