Fix for %#02x bug (shouldn't print 0x, but junk was printed) found by

Joren l'Ami.  Also fixes %p when arg is 0 (printed 0 instead of 0x0).
This commit is contained in:
Ben Gras 2006-07-21 10:08:47 +00:00
parent f6d1f6fdf6
commit 6c7004423d

View File

@ -80,7 +80,7 @@ o_print(va_list *ap, int flags, char *s, char c, int precision, int is_signed)
unsigned_val = signed_val; unsigned_val = signed_val;
} }
if ((flags & FL_ALT) && (c == 'o')) *s++ = '0'; if ((flags & FL_ALT) && (c == 'o')) *s++ = '0';
if (!unsigned_val) { if (!unsigned_val && c != 'p') {
if (!precision) if (!precision)
return s; return s;
} else if (((flags & FL_ALT) && (c == 'x' || c == 'X')) } else if (((flags & FL_ALT) && (c == 'x' || c == 'X'))
@ -268,7 +268,7 @@ _doprnt(register const char *fmt, va_list ap, FILE *stream)
*/ */
between_fill = 0; between_fill = 0;
if ((flags & FL_ZEROFILL) if ((flags & FL_ZEROFILL)
&& (((c == 'x' || c == 'X') && (flags & FL_ALT)) && (((c == 'x' || c == 'X') && (flags & FL_ALT) && j > 1)
|| (c == 'p') || (c == 'p')
|| ((flags & FL_SIGNEDCONV) || ((flags & FL_SIGNEDCONV)
&& ( *s1 == '+' || *s1 == '-' || *s1 == ' ')))) && ( *s1 == '+' || *s1 == '-' || *s1 == ' '))))