Skip to content

Commit b457f9b

Browse files
fixed regression: a valid precision must cause '0' to be ignored, for d i o u x X
1 parent c011302 commit b457f9b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

nanoprintf.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,20 @@ int npf_vpprintf(npf_putc pc, void *pc_ctx, char const *format, va_list args) {
816816
}
817817
#endif
818818

819+
#if NANOPRINTF_USE_PRECISION_FORMAT_SPECIFIERS == 1
820+
// For d i o u x X, the '0' flag must be ignored if a precision is provided
821+
if (fs.prec_opt != NPF_FMT_SPEC_OPT_NONE) {
822+
switch(fs.conv_spec) {
823+
case NPF_FMT_SPEC_CONV_SIGNED_INT:
824+
case NPF_FMT_SPEC_CONV_OCTAL:
825+
case NPF_FMT_SPEC_CONV_HEX_INT:
826+
case NPF_FMT_SPEC_CONV_UNSIGNED_INT:
827+
fs.leading_zero_pad = 0;
828+
break;
829+
}
830+
}
831+
#endif
832+
819833
union { char cbuf_mem[NANOPRINTF_CONVERSION_BUFFER_SIZE]; npf_uint_t binval; } u;
820834
char *cbuf = u.cbuf_mem, sign_c = 0;
821835
int cbuf_len = 0, need_0x = 0;

0 commit comments

Comments
 (0)