]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
crypto/bio/bio_print.c: handle negative width argument
authorEugene Syromiatnikov <esyr@openssl.org>
Tue, 5 Aug 2025 12:53:28 +0000 (14:53 +0200)
committerNeil Horman <nhorman@openssl.org>
Fri, 29 Aug 2025 16:18:30 +0000 (12:18 -0400)
Per [1]:

    A negative field width is taken as a '-' flag followed by a positive field
    width.

So, printf("%-*d", -12, 34) should lead to a 123-wide left-aligned output,
"34          ".

[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 1a0b2685018f1fbf47944978abecc849ec3449c8..67f24604a754ce913ea6a3dc6b2a169a33d8676a 100644 (file)
@@ -155,6 +155,10 @@ _dopr(char **sbuffer,
                 ch = *format++;
             } else if (ch == '*') {
                 min = va_arg(args, int);
+                if (min < 0) {
+                    flags |= DP_F_MINUS;
+                    min = -min;
+                }
                 ch = *format++;
                 state = DP_S_DOT;
             } else