Per [1] (emphasis is added):
- For o conversion, it shall increase the precision,
**if and only if necessary**, to force the first digit of the result
to be a zero (**if the value and precision are both 0,
a single 0 is printed**).
- For x or X conversion specifiers, a **non-zero** result shall have
0x (or 0X) prefixed to it.
[1] https://pubs.opengroup.org/onlinepubs/
9799919799//functions/printf.html
Signed-off-by: Eugene Syromiatnikov <esyr@openssl.org>
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/28177)
signvalue = ' ';
}
if (flags & DP_F_NUM) {
- if (base == 8)
- prefix = "0";
- if (base == 16)
- prefix = flags & DP_F_UP ? "0X" : "0x";
+ if (value != 0) {
+ if (base == 8)
+ prefix = "0";
+ if (base == 16)
+ prefix = flags & DP_F_UP ? "0X" : "0x";
+ }
}
if (flags & DP_F_UP)
caps = 1;