From 0f6e826f7b70770935b3766efad05d7755a74edc Mon Sep 17 00:00:00 2001 From: Eugene Syromiatnikov Date: Tue, 5 Aug 2025 15:11:08 +0200 Subject: [PATCH] crypto/bio/bio_print.c: no prefix for zero value in alternative form MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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) --- crypto/bio/bio_print.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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; -- 2.47.3