[Qt-interest] bug Qt 4.6-stable in qstrncpy
Sylvain Pointeau
sylvain.pointeau at gmail.com
Sun Oct 11 15:53:49 CEST 2009
Hi,
I think you are wrong.
extract from the qt documentation:
char * qstrncpy ( char * dst, const char * src, uint len )
A safe strncpy() function.
Copies at most len bytes from src (stopping at len or the terminating '\0'
whichever comes first) into dst and returns a pointer to dst. Guarantees
that dst is '\0'-terminated. If src or dst is 0, returns 0 immediately.
This function assumes that dst is at least len characters long.
beside :-) I use it for making a glue between C++ code and C code...
Cheers,
Sylvain
On Sun, Oct 11, 2009 at 3:34 PM, Thiago Macieira <thiago at kde.org> wrote:
> 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
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091011/48a09258/attachment.html
More information about the Qt-interest-old
mailing list