[PATCH] *printf: Violation of precision with null string

Jones Desougi jones.desougi at 27m.se
Thu Jun 10 13:04:51 UTC 2010


When a string format is processed and the argument is NULL, this yields
"(null)" regardless of precision. This does not make sense, precision
should not be exceeded. A simple test shows that glibc outputs nothing
if precision is smaller than six and the attached patch implements this
same behaviour.

Consider the not uncommon case of strings implemented like this:
struct string { int len; char *ptr; };
There is often no nultermination and they may be printed like this:
printf("%.*s", string.len, string.ptr);
If len is 0 then ptr may be anything, but NULL is a common value.
Obviously the empty string would be expected, not "(null)".

Signed-off-by: Jones Desougi <jones.desougi at 27m.se>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: uclibc-fix-printf-prec-with-null-string.patch
Type: text/x-patch
Size: 957 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/uclibc/attachments/20100610/9916d8d3/attachment.bin>


More information about the uClibc mailing list