From c8acaff52146e6b88cd82c344252c14faf985ba9 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 9 Dec 2015 21:44:08 -0500 Subject: SHERLOCK: Add validation for journal entry values --- engines/sherlock/journal.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'engines/sherlock/journal.cpp') diff --git a/engines/sherlock/journal.cpp b/engines/sherlock/journal.cpp index e443b6f727..c4aaa07a73 100644 --- a/engines/sherlock/journal.cpp +++ b/engines/sherlock/journal.cpp @@ -715,6 +715,15 @@ void Journal::record(int converseNum, int statementNum, bool replyOnly) { return; } + // Do a bit of validation here + assert(converseNum >= 0 && converseNum < (int)_directory.size()); + const Common::String &dirFilename = _directory[converseNum]; + Common::String locStr(dirFilename.c_str() + 4, dirFilename.c_str() + 6); + int newLocation = atoi(locStr.c_str()); + assert(newLocation >= 1 && newLocation <= (int)_locations.size()); + assert(!_locations[newLocation - 1].empty()); + assert(statementNum >= 0 && statementNum < (int)_vm->_talk->_statements.size()); + // Record the entry into the list _journal.push_back(JournalEntry(converseNum, statementNum, replyOnly)); _index = _journal.size() - 1; @@ -726,7 +735,7 @@ void Journal::record(int converseNum, int statementNum, bool replyOnly) { _index = saveIndex; _sub = saveSub; - // If new lines were added to the ournal, update the total number of lines + // If new lines were added to the journal, update the total number of lines // the journal continues if (!_lines.empty()) { _maxPage += _lines.size(); -- cgit v1.2.3