Note Common::String's behaviour may be undefined with \0 characters.

Also make operator=(char) and String(char) behave the same.

svn-id: r50712
This commit is contained in:
Willem Jan Palenstijn 2010-07-05 21:29:52 +00:00
parent 0c3cbcbfc5
commit a3202eab7c
2 changed files with 6 additions and 3 deletions

View file

@ -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;
}

View file

@ -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: