]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
crypto/bio/bio_print.c: no prefix for zero value in alternative form
authorEugene Syromiatnikov <esyr@openssl.org>
Tue, 5 Aug 2025 13:11:08 +0000 (15:11 +0200)
committerNeil Horman <nhorman@openssl.org>
Fri, 29 Aug 2025 16:18:30 +0000 (12:18 -0400)
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)

crypto/bio/bio_print.c

index 67f24604a754ce913ea6a3dc6b2a169a33d8676a..4681292a2d99cdae7e112b09ce5b4ea4b15bb8b1 100644 (file)
@@ -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;