[scummvm-devel] RFC: What should happen when adding \0 to a String?

Filippos Karapetis bluegr at gmail.com
Wed Jun 30 07:46:34 UTC 2021


IMHO, we should model Common::String's behavior after std::string.

In std::string, it is possible to add a \0 character, and it is not treated
as a terminator, plus, these characters count towards the string's length.
Check here:
https://akrzemi1.wordpress.com/2014/03/20/strings-length/

So, the best course of action would be to go with the third option, because
that's what std::string behaves like: \0 should be allowed, and it should
be part of the string itself (i.e. it should count towards it length, and
it should not terminate it).

Regards
Filippos

On Tue, Jun 29, 2021 at 3:33 PM Torbjörn Andersson via scummvm-devel <
scummvm-devel at lists.scummvm.org> wrote:

> Hi,
>
> A while back, there was some work done on unifying the String classes.
> I'm not familiar with the details of that, but apparently as a
> consequence of that some subtle behavior changed. The one In know about
> is adding a \0 character to a String, both whether it should be allowed
> at all and whether it should be counted as part of the String's length.
>
> This caused some problems (I know I fixed one in Myst), and a workaround
> was added so that adding \0 to a String does nothing. Unfortunately,
> there is at least one engine (ADL) that absolutely depends on this
> feature, and is now broken. This affects at least Hi-Res Adventures #5
> and #6.
>
> So the question here (and I really have no opinion myself) is, should it
> be possible to store \0 as part of a String, and if so exactly what
> should happen? The options I can think of are:
>
> - Nothing should happen. (This is the current behavior.)
> - It should be allowed, but it should terminate the string. (I.e.
> strings work like in C.)
> - It should be allowed, and it should not terminate the string. (I.e.
> strings can contain arbitrary binary data.)
>
> But maybe there is some other even more sensible behavior?
>
> Of course, whatever behavior we decide on we need to make sure
> everything works with it. At sev's suggestion, I've added a warning() to
> base-str.cpp to notify when \0 is added to a String. I have also gone
> through every game I've added to ScummVM to see whether or not it
> triggers the warning just by starting it and walking around for a bit.
>
> The results of my test can be found in
> http://www.update.uu.se/~d91tan/tmp/string.txt
>
> Note that some of the games I started are not even supported, and that
> there are some game engines where I don't own a single game. My list is
> far from exhaustive.
>
> Torbjörn Andersson
> _______________________________________________
> scummvm-devel mailing list
> scummvm-devel at lists.scummvm.org
> https://lists.scummvm.org/listinfo/scummvm-devel
>


-- 
"Experience is the name every one gives to their mistakes" - Oscar Wilde
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scummvm.org/pipermail/scummvm-devel/attachments/20210630/6478c838/attachment.htm>


More information about the scummvm-devel mailing list