From 162c198aabcdbe3795d34142c4707649f60fe499 Mon Sep 17 00:00:00 2001 From: dana Date: Sat, 29 Dec 2018 05:22:34 -0600 Subject: 43953: Fix rounding/truncation error in %. time-format specifier Also fixes an issue where %. couldn't be used more than once in a format string without strange results Tweaked very slightly per workers/43954 --- Src/utils.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'Src/utils.c') diff --git a/Src/utils.c b/Src/utils.c index e43a3cdb4..0969cef37 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -3334,19 +3334,28 @@ morefmt: #endif switch (*fmt++) { case '.': - if (ztrftimebuf(&bufsize, digs)) - return -1; + { + long fnsec = nsec; if (digs > 9) digs = 9; + if (ztrftimebuf(&bufsize, digs)) + return -1; if (digs < 9) { int trunc; - for (trunc = 8 - digs; trunc; trunc--) - nsec /= 10; - nsec = (nsec + 8) / 10; + long max = 100000000; + for (trunc = 8 - digs; trunc; trunc--) { + max /= 10; + fnsec /= 10; + } + max -= 1; + fnsec = (fnsec + 5) / 10; + if (fnsec > max) + fnsec = max; } - sprintf(buf, "%0*ld", digs, nsec); + sprintf(buf, "%0*ld", digs, fnsec); buf += digs; break; + } case '\0': /* Guard against premature end of string */ *buf++ = '%'; -- cgit v1.2.3 From 7951ede1dbb756aa3d6e81ee05fd9a63138066a1 Mon Sep 17 00:00:00 2001 From: dana Date: Sun, 30 Dec 2018 03:42:07 -0600 Subject: unposted (per 43938): Avoid segfault when unmetafying empty string --- ChangeLog | 5 +++++ Src/utils.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'Src/utils.c') diff --git a/ChangeLog b/ChangeLog index 2e37557df..61702caa8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2018-12-30 dana + + * unposted (per 43938): Src/utils.c: Avoid segfault when + unmetafying empty string + 2018-12-29 dana * 43953 (tweaked per 43954): Src/utils.c, Test/V09datetime.ztst: diff --git a/Src/utils.c b/Src/utils.c index 0969cef37..32f600858 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -3846,7 +3846,7 @@ sepjoin(char **s, char *sep, int heap) char sepbuf[2]; if (!*s) - return heap ? "" : ztrdup(""); + return heap ? dupstring("") : ztrdup(""); if (!sep) { /* optimise common case that ifs[0] is space */ if (ifs && *ifs != ' ') { -- cgit v1.2.3