[Scummvm-devel] zero bytes in Common::String

Willem Jan Palenstijn wjp at usecode.org
Tue Jun 29 12:31:25 CEST 2010


On Tue, Jun 29, 2010 at 02:21:34PM +0400, Vladimir Menshakov wrote:
> 
> 
> 29.06.10, 14:06, "Willem Jan Palenstijn" <wjp at usecode.org>:
> 
> > Hi,
> >  
> >  There's some confusion in Common::String about whether zero bytes are
> >  allowed in Common::String or not.
> >  
> >  The String::String(char c) constructor has an explicit comment saying it's
> >  allowed, but many methods use either c_str() internally or strcmp, strstr,
> >  ..., which might lead to surprising behaviour.
> >  
> >  And as fuzzie pointed out on IRC, String &String::operator=(char c) is
> >  also inconsistent with String::String(char c) in this respect.
> >  
> >  Any opinions on what we should do?
> >  
> >  Unless there's a reason we need zero byte support in strings, the easiest
> >  would be simply saying it's not allowed and leads to undefined behaviour.

> Why not to mimic all common strings classes and allow any data inside as long
> as you specify its length.  If not, legacy(and slow O(N)) const char * ctor /
> operator=() comes this way. 

I'm not saying we shouldn't, but if we do, we'd have to re-implement hasPrefix,
hasSuffix, contains, matchString, hash, compareTo, compareToIgnoreCase, and
whatever I'm missing.

Note that we currently already have a constructor String::String(const char
*str, uint32 len) that accepts zero bytes with any trouble.

-Willem Jan




More information about the Scummvm-devel mailing list