[Qt-interest] bug Qt 4.6-stable in qstrncpy

Sylvain Pointeau sylvain.pointeau at gmail.com
Sun Oct 11 15:04:10 CEST 2009


Hi,
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.

char *qstrncpy(char *dst, const char *src, uint len)

{

    if (!src || !dst)

        return 0;

#if defined(_MSC_VER) && _MSC_VER >= 1400

strncpy_s(dst, len, src, len-1);

#else

    strncpy(dst, src, len);

#endif

    if (len > 0)

        dst[len-1] = '\0'; <--------------- HERE THERE IS A MISTAKE

    return dst;

}

Cheers,
Sylvain
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091011/b166ca8d/attachment.html 


More information about the Qt-interest-old mailing list