aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorJonathan Gray2002-09-15 09:06:58 +0000
committerJonathan Gray2002-09-15 09:06:58 +0000
commit9ce78dd66e5b893bcfe8629ca1e880ab7c10682d (patch)
tree700264d2dbeabecaba599e55208fafe1c37e6c12 /common
parente6751d0d8f49e326ea7b1f6f506d1a9dfbd875db (diff)
downloadscummvm-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
Diffstat (limited to 'common')
-rw-r--r--common/str.cpp16
-rw-r--r--common/util.cpp20
-rw-r--r--common/util.h3
3 files changed, 31 insertions, 8 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