From a3202eab7c710b63b1ede3acc54c0d87a7d05b1d Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Mon, 5 Jul 2010 21:29:52 +0000 Subject: Note Common::String's behaviour may be undefined with \0 characters. Also make operator=(char) and String(char) behave the same. svn-id: r50712 --- common/str.cpp | 6 +++--- common/str.h | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'common') 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: -- cgit v1.2.3