[uClibc]Bug in printf.c ("%c",0)

Johan Adolfsson johan.adolfsson at axis.com
Mon May 7 15:09:42 UTC 2001


The length is not correct when doing printf("%c",0)
the following patch seems to fix that, but there might be better ways...
(linenumbers might not be the same as you have)

On April 26 I also posted another printf.c patch suggestion that
unrolled the loop in asprintf, making the generated code smaller
and removed the warning, any comments on that?
(Those with arm, mips and ppc could try it and
see if the code gets smaller for those platforms too (atleast with -O2 ))

/Johan - Axis Communications AB


@@ -356,7 +356,7 @@ static const char u_radix[] = "\x02\x08\

 int vfnprintf(FILE * op, size_t max_size, const char *fmt, va_list ap)
 {
-       int i, cnt, lval;
+       int i, cnt, lval, len;
        char *p;
        const char *fmt0;
        int buffer_mode;
@@ -558,6 +558,9 @@ int vfnprintf(FILE * op, size_t max_size
                                        if (*p == 'c') {        /* character
*/
                                                p = tmp;
                                                *p = va_arg(ap, int);
+                                               /* This takes care of the
"%c",0 case */
+                                               len = 1;
+                                               goto print_len_set;
                                        } else {        /* string */
                                                p = va_arg(ap, char *);
                                                if (!p) {
@@ -589,11 +592,10 @@ int vfnprintf(FILE * op, size_t max_size
                        print:
 #endif
                                {                               /* this used
to be printfield */
-                                       int len;

                                        /* cheaper than strlen call */
                                        for ( len = 0 ; p[len] ; len++ ) { }
-
+                       print_len_set:
                                        if ((*p == '-')
 #if WANT_GNU_ERRNO
                                                && (*fmt != 'm')







More information about the uClibc mailing list