From b99fa6ba8c7f4a5407ff59812e5e6023c8a3301c Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Mon, 9 May 2016 20:42:55 -0400 Subject: TITANIC: Fix to SimpleFile scanf --- engines/titanic/support/simple_file.cpp | 15 +++++++++++++-- engines/titanic/true_talk/tt_string.cpp | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/engines/titanic/support/simple_file.cpp b/engines/titanic/support/simple_file.cpp index 18a75864a8..85f42aeeb5 100644 --- a/engines/titanic/support/simple_file.cpp +++ b/engines/titanic/support/simple_file.cpp @@ -368,23 +368,34 @@ bool SimpleFile::scanf(const char *format, ...) { CString formatStr(format); while (!formatStr.empty()) { if (formatStr.hasPrefix(" ")) { + // Skip over whitespaces formatStr.deleteChar(0); - safeRead(&c, 1); + safeRead(&c, 1); if (!Common::isSpace(c)) return false; + + while (Common::isSpace(c)) + safeRead(&c, 1); + _inStream->skip(-1); } else if (formatStr.hasPrefix("%d")) { // Read in a number formatStr = CString(formatStr.c_str() + 2); int *param = (int *)va_arg(va, int *); *param = readNumber(); + + if (!eos()) + _inStream->skip(-1); } else if (formatStr.hasPrefix("%s")) { // Read in text until the next space formatStr = CString(formatStr.c_str() + 2); CString *str = (CString *)va_arg(va, CString *); str->clear(); - while (!eos() && (c = readByte()) != ' ') + while (!eos() && !Common::isSpace(c = readByte())) *str += c; + + if (!eos()) + _inStream->skip(-1); } } diff --git a/engines/titanic/true_talk/tt_string.cpp b/engines/titanic/true_talk/tt_string.cpp index ffe6509e07..2308afa75d 100644 --- a/engines/titanic/true_talk/tt_string.cpp +++ b/engines/titanic/true_talk/tt_string.cpp @@ -54,7 +54,7 @@ TTString::TTString(TTString &str) { } TTString::~TTString() { - if (--_data->_referenceCount == 0) + if (_data && --_data->_referenceCount == 0) delete _data; } -- cgit v1.2.3