diff options
author | Jonathan Gray | 2002-09-15 09:06:58 +0000 |
---|---|---|
committer | Jonathan Gray | 2002-09-15 09:06:58 +0000 |
commit | 9ce78dd66e5b893bcfe8629ca1e880ab7c10682d (patch) | |
tree | 700264d2dbeabecaba599e55208fafe1c37e6c12 | |
parent | e6751d0d8f49e326ea7b1f6f506d1a9dfbd875db (diff) | |
download | scummvm-rg350-9ce78dd66e5b893bcfe8629ca1e880ab7c10682d.tar.gz scummvm-rg350-9ce78dd66e5b893bcfe8629ca1e880ab7c10682d.tar.bz2 scummvm-rg350-9ce78dd66e5b893bcfe8629ca1e880ab7c10682d.zip |
apply patch #609508 real fix for MI2 Dialog Box crash, by CCCP at Endy's request
svn-id: r4943
-rw-r--r-- | common/str.cpp | 16 | ||||
-rw-r--r-- | common/util.cpp | 20 | ||||
-rw-r--r-- | common/util.h | 3 | ||||
-rw-r--r-- | gui/gui.cpp | 14 |
4 files changed, 40 insertions, 13 deletions
diff --git a/common/str.cpp b/common/str.cpp index 1229c14566..85ceb965d4 100644 --- a/common/str.cpp +++ b/common/str.cpp @@ -20,15 +20,15 @@ #include "stdafx.h" #include "str.h" - +#include "util.h" namespace ScummVM { String::String(const char *str) { _refCount = new int(1); - if (str) { - _capacity = _len = strlen(str); + if (str) { + _capacity = _len = resStrLen(str); _str = (char *)calloc(1, _capacity+1); memcpy(_str, str, _len+1); } else { @@ -41,8 +41,8 @@ String::String(const ConstString &str) { printf("String::String(const ConstString &str)\n"); _refCount = new int(1); - if (str._str) { - _capacity = _len = strlen(str._str); + if (str._str) { + _capacity = _len = resStrLen(str._str); _str = (char *)calloc(1, _capacity+1); memcpy(_str, str._str, _len+1); } else { @@ -77,8 +77,8 @@ void String::decRefCount() } String& String::operator =(const char* str) -{ - int len = strlen(str); +{ + int len = resStrLen(str); if (len > 0) { ensureCapacity(len, false); @@ -111,7 +111,7 @@ String& String::operator =(const String& str) String& String::operator +=(const char* str) { - int len = strlen(str); + int len = resStrLen(str); if (len > 0) { ensureCapacity(_len + len, true); diff --git a/common/util.cpp b/common/util.cpp index 7ff4a9e032..86711866c9 100644 --- a/common/util.cpp +++ b/common/util.cpp @@ -120,3 +120,23 @@ void hexdump(const byte * data, int len) printf(" "); printf("|\n"); } + +// Resource string length, supports special chars starting with FF +int resStrLen(const char *src) +{ + int num = 0; + byte chr; + while ((chr = *src++) != 0) { + num++; + if (chr == 255) { + chr = *src++; + num++; + + if (chr != 1 && chr != 2 && chr != 3 && chr != 8) { + src += 2; + num += 2; + } + } + } + return num; +} diff --git a/common/util.h b/common/util.h index afaf2acaf4..79a6eb1068 100644 --- a/common/util.h +++ b/common/util.h @@ -48,4 +48,7 @@ void ClearBlendCache(byte *palette, int weight); */ void hexdump(const byte * data, int len); +// Resource string length +int resStrLen(const char *src); + #endif diff --git a/gui/gui.cpp b/gui/gui.cpp index 8d127226e2..96c74fd469 100644 --- a/gui/gui.cpp +++ b/gui/gui.cpp @@ -287,7 +287,6 @@ const GuiWidget pause_dialog[] = { {0, 0, 0, 0, 0, 0, 0, 0, 0} }; - void Gui::draw(int start, int end) { int i; @@ -419,8 +418,15 @@ void Gui::drawWidget(const GuiWidget *w) break; case GUI_RESTEXT: s = queryString(w->_string_number, w->_id); - if (s) - strcpy(text, s); + if (s) { + int t = resStrLen(s); + if (t >= 500) { // probably won't happen, but just in case... + warning("Resource string is too long, truncating"); + t = 498; + text[499] = '\0'; + } + memcpy(text, s, t+1); + } break; case GUI_VARTEXT: sprintf(text, "%s %d", string_map_table_custom[w->_string_number], @@ -907,8 +913,6 @@ void Gui::getSavegameNames(int start) const char *Gui::queryString(int stringno, int id) { - if ((stringno == 1) && (_s->_gameId == GID_MONKEY2)) return "How may I serve you?"; // FIXME (MI2 data file is wrong) - static char namebuf[64]; char *result; int string; |