Zero prefix in the alternative octal form count towards precision,
per [1]:
For o conversion, it **shall increase the precision**...
[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)
size_t *currlen,
size_t *maxlen, int64_t value, int base, int min, int max, int flags)
{
+ static const char oct_prefix[] = "0";
+
int signvalue = 0;
const char *prefix = "";
uint64_t uvalue;
if (flags & DP_F_NUM) {
if (value != 0) {
if (base == 8)
- prefix = "0";
+ prefix = oct_prefix;
if (base == 16)
prefix = flags & DP_F_UP ? "0X" : "0x";
}
place--;
convert[place] = 0;
- zpadlen = max - place;
+ /*
+ * "#" (alternative form):
+ * - 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
+ */
+ zpadlen = max - place - (prefix == oct_prefix);
spadlen =
min - OSSL_MAX(max, place) - (signvalue ? 1 : 0) - (int)strlen(prefix);
if (zpadlen < 0)