]> diplodocus.org Git - nmh/commitdiff
Fix bug in cpnumber().
authorKen Hornstein <kenh@pobox.com>
Thu, 17 Aug 2017 05:24:08 +0000 (01:24 -0400)
committerKen Hornstein <kenh@pobox.com>
Thu, 17 Aug 2017 05:24:08 +0000 (01:24 -0400)
The cpnumber() function (which handles the NUMF instruction, among others)
would hang if a 0 width was given to it.  Make sure that (and negative
widths) are handled correctly.  Note that normally NUMF did not handle
left padding which is indicated by a negative width; that may change
in the future.

sbr/fmt_scan.c

index 8e59669..50d7c4c 100644 (file)
@@ -67,7 +67,12 @@ match (char *str, char *sub)
  * copy a number to the destination subject to a maximum width
  */
 void
-cpnumber(charstring_t dest, int num, unsigned int wid, char fill, size_t max) {
+cpnumber(charstring_t dest, int num, int wid, char fill, size_t max) {
+    /* Maybe we should handle left padding at some point? */
+    if (wid == 0)
+       return;
+    if (wid < 0)
+       wid = -wid;
     if (wid < (num >= 0 ? max : max-1)) {
        /* Build up the string representation of num in reverse. */
        charstring_t rev = charstring_create (0);