printf: string precision "%.*s" give (null) string

Lennart Sorensen lsorense at csclub.uwaterloo.ca
Fri Nov 6 15:49:53 UTC 2009


On Fri, Nov 06, 2009 at 04:15:14PM +0100, Peter Lukac wrote:
> Hello,
> I use uclibc version 0.9.29 on arm.
> I think that function printf not work right with precision for string.
> 
> here is my simple program:
> 
> #include <stdio.h>
> int main()
> {
>     char *p = NULL;
>     printf("\n--->%.*s<---", 0, p);
>     printf("\n--->%.*s<---", 3, p);
>     printf("\n--->%.*s<---\n", 6, p);
> 
>     return 0;
> }
> 
> on glibc it works fine. i get output : 
> ---><---
> ---><---
> --->(null)<---
> 
> but in uclibc i get
> 
> --->(null)<---
> --->(null)<---
> --->(null)<---
> 
> I think that if precision .* parameter is 0 or is less as string length,
> printf should be print empty string "" and not "(null)" string. 
> 
> Is it bug or feature? :)
>  
> i'm using pjlib where is used lot of code with "%.*s" argument which don't 
> work correctly.
> 
> ...have a nice day

What does it do with real strings rather than the odd '(null)' label
for a non existant string?

-- 
Len Sorensen


More information about the uClibc mailing list