Author: Kev <klmitch@mit.edu>
[ircu2.10.12-pk.git] / ircd / ircd_snprintf.c
index 6c9e43db5b54d597c01d73694872eb5ddd7b66a4..2cbf74178defba9eb3178cc26996b0448e8d5aa8 100644 (file)
@@ -1820,9 +1820,6 @@ doprintf(struct Client *dest, struct BufData *buf_p, const char *fmt,
       char intbuf[INTBUF_LEN], **table = 0, *tstr;
       int ibuf_loc = INTBUF_LEN, ilen, zlen = 0, plen = 0, elen = 0;
 
-      if (fld_s.prec < 0) /* default precision is 1 */
-       fld_s.prec = 1;
-
       if (fld_s.base == BASE_OCTAL) /* select string table to use */
        table = octal;
       else if (fld_s.base == BASE_DECIMAL)
@@ -1833,6 +1830,15 @@ doprintf(struct Client *dest, struct BufData *buf_p, const char *fmt,
          elen = 2; /* account for the length of 0x */
       }
 
+      if (fld_s.prec < 0) { /* default precision is 1 */
+       if ((fld_s.flags & (FLAG_MINUS | FLAG_ZERO)) == FLAG_ZERO &&
+           fld_s.width) {
+         fld_s.prec = fld_s.width - elen;
+         fld_s.width = 0;
+       } else
+         fld_s.prec = 1;
+      }
+
       /* If there's a sign flag, account for it */
       if (fld_s.flags & (FLAG_PLUS | FLAG_SPACE | INFO_NEGATIVE))
        elen++;