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

Peter Lukac p.lukac at emtest.sk
Mon Nov 9 09:00:22 UTC 2009


On Friday 06 November 2009 04:49:53 pm you wrote:
> 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?

Hello,
Hmm...do you want know how it works with real string? here is example:

#include <stdio.h>
int main()
{
    char *p = NULL;
    const char *p2 = "Hello World";

    printf("\n--->%.*s<---", 0, p);
    printf("\n--->%.*s<---", 3, p);
    printf("\n--->%.*s<---\n", 6, p);

    printf("\n--->%.*s<---", 0, p2);
    printf("\n--->%.*s<---", 4, p2);
    printf("\n--->%.*s<---\n", 11, p2);
    return 0;
}

with glibc on i386 :

---><---
---><---
--->(null)<---

---><---
--->Hell<---
--->Hello World<---

and on ARM with uclibc:

--->(null)<---
--->(null)<---
--->(null)<---

---><---
--->Hell<---
--->Hello World<---


i think with real string it works fine...

...thx














More information about the uClibc mailing list