[Qt-interest] QString::fromAscii can run past end of string
Bob Babcock
wssddc at nospam.gis.net
Thu Apr 15 08:39:02 CEST 2010
Thiago Macieira <thiago at kde.org> wrote in
news:201004140852.50900.thiago at kde.org:
> The documentation says the second parameter *is* the size, not the
> maximum length.
>
> It also says that "If size is -1 (default), it is taken to be
> qstrlen(str)."
>
> So when you do:
> fromAscii("This\0isatest", 14);
>
> You get a Unicode string of 14 codepoints, with a U+0000 in the fifth
> position.
I'm still surprised that it goes past the terminating null. It's such an
unlikely thing to want to do that I assumed the documentation was just not
mentioning how this case was handled. I do agree that the code does
exactly what a literal reading of the documentation says.
More information about the Qt-interest-old
mailing list