|
@@ -284,6 +284,7 @@ char *number(char *buf, char *end, unsigned long long num,
|
|
|
char locase;
|
|
|
int need_pfx = ((spec.flags & SPECIAL) && spec.base != 10);
|
|
|
int i;
|
|
|
+ bool is_zero = num == 0LL;
|
|
|
|
|
|
/* locase = 0 or 0x20. ORing digits or letters with 'locase'
|
|
|
* produces same digits or (maybe lowercased) letters */
|
|
@@ -305,8 +306,9 @@ char *number(char *buf, char *end, unsigned long long num,
|
|
|
}
|
|
|
}
|
|
|
if (need_pfx) {
|
|
|
- spec.field_width--;
|
|
|
if (spec.base == 16)
|
|
|
+ spec.field_width -= 2;
|
|
|
+ else if (!is_zero)
|
|
|
spec.field_width--;
|
|
|
}
|
|
|
|
|
@@ -353,9 +355,11 @@ char *number(char *buf, char *end, unsigned long long num,
|
|
|
}
|
|
|
/* "0x" / "0" prefix */
|
|
|
if (need_pfx) {
|
|
|
- if (buf < end)
|
|
|
- *buf = '0';
|
|
|
- ++buf;
|
|
|
+ if (spec.base == 16 || !is_zero) {
|
|
|
+ if (buf < end)
|
|
|
+ *buf = '0';
|
|
|
+ ++buf;
|
|
|
+ }
|
|
|
if (spec.base == 16) {
|
|
|
if (buf < end)
|
|
|
*buf = ('X' | locase);
|