[Scummvm-cvs-logs] CVS: scummvm/common str.cpp,1.3,1.4 util.cpp,1.3,1.4 util.h,1.3,1.4
Jonathan Gray
khalek at users.sourceforge.net
Sun Sep 15 02:07:01 CEST 2002
Update of /cvsroot/scummvm/scummvm/common
In directory usw-pr-cvs1:/tmp/cvs-serv21258
Modified Files:
str.cpp util.cpp util.h
Log Message:
apply patch #609508 real fix for MI2 Dialog Box crash, by CCCP at Endy's request
Index: str.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/str.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- str.cpp 9 Sep 2002 11:42:24 -0000 1.3
+++ str.cpp 15 Sep 2002 09:06:02 -0000 1.4
@@ -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);
Index: util.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/util.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- util.cpp 8 Sep 2002 01:08:11 -0000 1.3
+++ util.cpp 15 Sep 2002 09:06:02 -0000 1.4
@@ -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;
+}
Index: util.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/util.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- util.h 8 Sep 2002 01:08:11 -0000 1.3
+++ util.h 15 Sep 2002 09:06:02 -0000 1.4
@@ -48,4 +48,7 @@
*/
void hexdump(const byte * data, int len);
+// Resource string length
+int resStrLen(const char *src);
+
#endif
More information about the Scummvm-git-logs
mailing list