From 58fa16ef1e6d6c3a698d220409416bccec187287 Mon Sep 17 00:00:00 2001 From: Ken Hornstein Date: Thu, 17 Aug 2017 01:24:08 -0400 Subject: [PATCH] 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. --- sbr/fmt_scan.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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); -- 2.56.0