]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: allow discerning unspec width in printfrr ext
authorDavid Lamparter <equinox@diac24.net>
Fri, 26 Mar 2021 16:58:54 +0000 (17:58 +0100)
committerDavid Lamparter <equinox@diac24.net>
Tue, 30 Mar 2021 20:32:59 +0000 (22:32 +0200)
With 0 currently the default value for the width specifier, it's not
possible to discern that from a %*p where 0 was passed as the length
parameter.  Use -1 to allow for that.

Signed-off-by: David Lamparter <equinox@diac24.net>
lib/printf/vfprintf.c
lib/printfrr.h

index 7fafa89aa70e9d193ed215f4849a74e8b48099c5..1bd24743ee14faf988412488768ce0ac7ad9262a 100644 (file)
@@ -305,7 +305,7 @@ vbprintfrr(struct fbuf *cb_in, const char *fmt0, va_list ap)
 
                flags = 0;
                dprec = 0;
-               width = 0;
+               width = -1;
                prec = -1;
                sign = '\0';
                ox[1] = '\0';
@@ -688,6 +688,9 @@ number:                     if ((dprec = prec) >= 0)
                 * Compute actual size, so we know how much to pad.
                 * size excludes decimal prec; realsz includes it.
                 */
+               if (width < 0)
+                       width = 0;
+
                realsz = dprec > size ? dprec : size;
                if (sign)
                        realsz++;
@@ -750,6 +753,9 @@ ext_printed:
                 * Keep analogous to code above please.
                 */
 
+               if (width < 0)
+                       width = 0;
+
                realsz = size;
                prsize = width > realsz ? width : realsz;
                if ((unsigned int)ret + prsize > INT_MAX) {
index 754cb09598e9eb6060ee1d0eb6c8eaf1ad4a8250..9dd20f0a8ff677bba9082877cc32edc2ebb07a2b 100644 (file)
@@ -178,6 +178,23 @@ struct printfrr_eargs {
        bool leftadj;
 };
 
+/* for any extension that needs a buffer length */
+
+static inline ssize_t printfrr_ext_len(struct printfrr_eargs *ea)
+{
+       ssize_t rv;
+
+       if (ea->precision >= 0)
+               rv = ea->precision;
+       else if (ea->width >= 0) {
+               rv = ea->width;
+               ea->width = -1;
+       } else
+               rv = -1;
+
+       return rv;
+}
+
 /* no locking - must be called when single threaded (e.g. at startup.)
  * this restriction hopefully won't be a huge bother considering normal usage
  * scenarios...