aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorWillem Jan Palenstijn2010-07-05 21:29:52 +0000
committerWillem Jan Palenstijn2010-07-05 21:29:52 +0000
commita3202eab7c710b63b1ede3acc54c0d87a7d05b1d (patch)
tree6c359c4bb1a014b431e089c8915837b4e8d9201f /common
parent0c3cbcbfc57c6c355d7106aa6be3faa7dd2f8590 (diff)
downloadscummvm-rg350-a3202eab7c710b63b1ede3acc54c0d87a7d05b1d.tar.gz
scummvm-rg350-a3202eab7c710b63b1ede3acc54c0d87a7d05b1d.tar.bz2
scummvm-rg350-a3202eab7c710b63b1ede3acc54c0d87a7d05b1d.zip
Note Common::String's behaviour may be undefined with \0 characters.
Also make operator=(char) and String(char) behave the same. svn-id: r50712
Diffstat (limited to 'common')
-rw-r--r--common/str.cpp6
-rw-r--r--common/str.h3
2 files changed, 6 insertions, 3 deletions
diff --git a/common/str.cpp b/common/str.cpp
index 50b9bdb879..744ba46ec7 100644
--- a/common/str.cpp
+++ b/common/str.cpp
@@ -105,8 +105,6 @@ String::String(char c)
_storage[0] = c;
_storage[1] = 0;
- // TODO/FIXME: There is no reason for the following check -- we *do*
- // allow strings to contain 0 bytes!
_size = (c == 0) ? 0 : 1;
}
@@ -256,9 +254,11 @@ String &String::operator=(const String &str) {
String &String::operator=(char c) {
decRefCount(_extern._refCount);
_str = _storage;
- _size = 1;
+
_str[0] = c;
_str[1] = 0;
+
+ _size = (c == 0) ? 0 : 1;
return *this;
}
diff --git a/common/str.h b/common/str.h
index 189c37adb4..e3dec6cdc2 100644
--- a/common/str.h
+++ b/common/str.h
@@ -39,6 +39,9 @@ namespace Common {
* Instead, small strings are stored 'inside' the string object (i.e. on
* the stack, for stack allocated objects), and only for strings exceeding
* a certain length do we allocate a buffer on the heap.
+ *
+ * The presence of \0 characters in the string will cause undefined
+ * behaviour in some operations.
*/
class String {
protected: