[syslinux] [PATCH] syslinux/com32: Fix the printing of left zero padded hexadecimals with a leading '0x'.

Brett Walker brett.walker at geometry.com.au
Thu Feb 8 03:01:21 PST 2018


From: Brett Walker <brett.walker at geometry.com.au>

When printing hexadecimal numbers to a fixed width, padded with leading zeros,
and also having a leading '0x'; the resultant string can be shortened by up to
two characters if any leading zero padding character required is.

    int hexnum = 0x00001234;

    printf("%08X", hexnum);  // results in 00001234
    printf("%#08X", hexnum); // results in 0x001234

To correct this, the zero padding counting logic needs to use ndigits instead of
nchars.

Signed-off-by: Brett Walker <brett.walker at geometry.com.au>

---

--- ./syslinux/com32/lib/vsnprintf.c.orig
+++ ./syslinux/com32/lib/vsnprintf.c
@@ -126,7 +126,7 @@ format_int(char *q, size_t n, uintmax_t

     /* Emit zero padding */
     if ((flags & (FL_MINUS | FL_ZERO)) == FL_ZERO && width > ndigits) {
- while (width > nchars) {
+        while (width > ndigits) {
      EMIT('0');
      width--;
  }



More information about the Syslinux mailing list