From: Eugene Syromiatnikov Date: Tue, 5 Aug 2025 13:11:08 +0000 (+0200) Subject: crypto/bio/bio_print.c: no prefix for zero value in alternative form X-Git-Tag: openssl-3.6.0-alpha1~42 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0f6e826f7b70770935b3766efad05d7755a74edc;p=thirdparty%2Fopenssl.git crypto/bio/bio_print.c: no prefix for zero value in alternative form 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 Reviewed-by: Saša Nedvědický Reviewed-by: Neil Horman (Merged from https://github.com/openssl/openssl/pull/28177) --- diff --git a/crypto/bio/bio_print.c b/crypto/bio/bio_print.c index 67f24604a75..4681292a2d9 100644 --- a/crypto/bio/bio_print.c +++ b/crypto/bio/bio_print.c @@ -474,10 +474,12 @@ fmtint(char **sbuffer, 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;