aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2011-11-01 12:11:47 +1100
committerPaul Gilbert2011-11-01 12:11:47 +1100
commitf14d3e0276d159dbcbab4582c47cde5c86dd5389 (patch)
tree029bcec1fbbc912512761ec21255fb362359cca2
parent66a013d1f71e85477cd8e10bf3f2af46aca64765 (diff)
downloadscummvm-rg350-f14d3e0276d159dbcbab4582c47cde5c86dd5389.tar.gz
scummvm-rg350-f14d3e0276d159dbcbab4582c47cde5c86dd5389.tar.bz2
scummvm-rg350-f14d3e0276d159dbcbab4582c47cde5c86dd5389.zip
TSAGE: Bugfix for reading messages with an invalid line number
-rw-r--r--engines/tsage/resources.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/engines/tsage/resources.cpp b/engines/tsage/resources.cpp
index 652ab32350..b8c8fcdeea 100644
--- a/engines/tsage/resources.cpp
+++ b/engines/tsage/resources.cpp
@@ -414,16 +414,27 @@ byte *TLib::getSubResource(int resNum, int rlbNum, int index, uint *size, bool s
*/
bool TLib::getMessage(int resNum, int lineNum, Common::String &result, bool suppressErrors) {
byte *msgData = getResource(RES_MESSAGE, resNum, 0, true);
- if (!msgData) {
+ if (!msgData || (lineNum < 0)) {
if (suppressErrors)
return false;
error("Unknown message %d line %d", resNum, lineNum);
}
+ int msgSize = _memoryManager.getSize(msgData);
const char *srcP = (const char *)msgData;
- while (lineNum-- > 0)
+ const char *endP = srcP + msgSize;
+
+ while (lineNum-- > 0) {
srcP += strlen(srcP) + 1;
+
+ if (srcP >= endP) {
+ if (suppressErrors)
+ return false;
+
+ error("Unknown message %d line %d", resNum, lineNum);
+ }
+ }
result = Common::String(srcP);
_memoryManager.deallocate(msgData);
@@ -503,7 +514,7 @@ Common::String ResourceManager::getMessage(int resNum, int lineNum, bool suppres
if (!suppressErrors)
error("Unknown message %d line %d", resNum, lineNum);
- return result;
+ return Common::String();
}
} // end of namespace TsAGE