From: Ken Hornstein Date: Thu, 17 Aug 2017 05:24:08 +0000 (-0400) Subject: Fix bug in cpnumber(). X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/58fa16ef1e6d6c3a698d220409416bccec187287?ds=inline Fix bug in cpnumber(). 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. --- diff --git a/sbr/fmt_scan.c b/sbr/fmt_scan.c index 8e59669d..50d7c4ca 100644 --- a/sbr/fmt_scan.c +++ b/sbr/fmt_scan.c @@ -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);