crypto/bio/bio_print.c: handle the case of 0 with zero precision

Per [1]:

    The result of converting zero with an explicit precision of zero
    shall be no characters.

[1] https://pubs.opengroup.org/onlinepubs/9699919799/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)
This commit is contained in:
Eugene Syromiatnikov 2025-08-15 16:35:11 +02:00 committed by Neil Horman
parent ac49202722
commit c5e3e7bfb6
1 changed files with 5 additions and 4 deletions

View File

@ -549,20 +549,21 @@ fmtint(struct pr_desc *desc,
signvalue = ' ';
}
if (flags & DP_F_NUM) {
if (base == 8)
prefix = oct_prefix;
if (value != 0) {
if (base == 8)
prefix = oct_prefix;
if (base == 16)
prefix = flags & DP_F_UP ? "0X" : "0x";
}
}
if (flags & DP_F_UP)
caps = 1;
do {
/* When 0 is printed with an explicit precision 0, the output is empty. */
while (uvalue && (place < (int)sizeof(convert))) {
convert[place++] = (caps ? "0123456789ABCDEF" : "0123456789abcdef")
[uvalue % (unsigned)base];
uvalue = (uvalue / (unsigned)base);
} while (uvalue && (place < (int)sizeof(convert)));
}
if (place == sizeof(convert))
place--;
convert[place] = 0;