swprintf - terminating null in case n < input length
Petr Muller
pmuller@redhat.com
Tue Aug 19 15:41:00 GMT 2008
Hi,
I'm curious about the behavior of swprintf function in the case n is
lower than input length. POSIX says that the 'terminating zero shall be
always added' and (in 'return code') 'if n or more characters were
requested to write, swprintf should return -1'. glibc's swprintf seems
to not add the zero in this case, so for
wchar_t input[7] = L"6chars\0"
wchar_t buffer[10] = L"---------\0"
swprintf(buffer, 5, L"%ls", input);
you will get buffer = "6cha-----\0", which is 4 characters copied and
missing null. -1 returned.
Is this behavior a bug, or is it intentional (aka: n < input length is
an error, thus the side effect on the buffers is not defined)?
I've already traced this to the source and can provide a patch, but I'm
not sure if that behavior is really a bug.
Petr
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
URL: <http://sourceware.org/pipermail/libc-help/attachments/20080819/a342d7d3/attachment.sig>
More information about the Libc-help
mailing list