--- gui_old.cpp Wed Sep 11 06:28:32 2002 +++ gui_new.cpp Sun Sep 15 01:21:38 2002 @@ -287,7 +287,6 @@ {0, 0, 0, 0, 0, 0, 0, 0, 0} }; - void Gui::draw(int start, int end) { int i; @@ -419,8 +418,15 @@ 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 @@ 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; --- str_old.cpp Mon Sep 09 04:42:24 2002 +++ str_new.cpp Sun Sep 15 01:03:16 2002 @@ -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 @@ { 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 @@ } 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 char* str) { - int len = strlen(str); + int len = resStrLen(str); if (len > 0) { ensureCapacity(_len + len, true); --- util_old.cpp Sat Sep 07 18:08:12 2002 +++ util_new.cpp Sun Sep 15 01:09:42 2002 @@ -120,3 +120,23 @@ 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; +} --- util_old.h Sat Sep 07 18:08:12 2002 +++ util_new.h Sun Sep 15 00:41:28 2002 @@ -48,4 +48,7 @@ */ void hexdump(const byte * data, int len); +// Resource string length +int resStrLen(const char *src); + #endif