[Qt-interest] bug Qt 4.6-stable in qstrncpy
Thiago Macieira
thiago at kde.org
Sun Oct 11 15:34:48 CEST 2009
Em Domingo 11. Outubro 2009, às 15.04.10, Sylvain Pointeau escreveu:
> I found a mistake in qstrncpy
> it copies only the len-1 bytes
> or more exactly it finishes by putting a 0 at len-1 which is obviously
> wrong.
That is intentional, so it's not a bug. The last parameter is not the length
of the string you want to copy, but the size of the destination buffer.
const char *original = "This is a very long string";
char buf[5];
qstrncpy(buf, original, sizeof buf);
Result: buf contains "This";
Besides, why are you using this function?
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Senior Product Manager - Nokia, Qt Development Frameworks
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
Qt Developer Days 2009 | Registration Now Open!
Munich, Germany: Oct 12 - 14 San Francisco, California: Nov 2 - 4
http://qt.nokia.com/qtdevdays2009
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091011/a4419334/attachment.bin
More information about the Qt-interest-old
mailing list