From 12fd48bd846a44e05a03a007beeb848d6de7604c Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sun, 8 Aug 2021 15:20:11 -0700 Subject: [PATCH] =?utf8?q?remove=20fallback=20"%=3F%K"=20strftime=20format?= =?utf8?q?=20in=20expr=E2=80=99s=20printf?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit lib/expr’s printf implementation supports a "%t" format code to print a time. If no format is provided for this, it would fallback to a default of "%?%K". While working on #1998, one of my intermediate refactorings moved this string literal into the actual call to strftime. At this point the compiler politely interjected that neither "%?" nor "%K" are format strings understood by strftime. So it seems this results in an invalid call to strftime. To deal with this, we now throw an error when this function is called with no format string instead of making an invalid strftime call. --- CHANGELOG.md | 1 + lib/expr/exeval.c | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aad5d05c4..1e1c2e054 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `edgepaint` accepts more standard `--` prefixed command line arguments and rejects invalid options #1971 - improved detection of Lefty dependencies in the Autotools build system +- libexpr rejects printing the time (`%t`) if no format is provided ### Fixed diff --git a/lib/expr/exeval.c b/lib/expr/exeval.c index ea7fc9e33..6b4ce791c 100644 --- a/lib/expr/exeval.c +++ b/lib/expr/exeval.c @@ -348,12 +348,14 @@ prformat(Sfio_t* sp, void* vp, Sffmt_t* dp) case 'T': if ((tm = *(Sflong_t*)vp) == -1) tm = time(NULL); - if (!txt) - txt = "%?%K"; - s = fmtbuf(TIME_LEN); - stm = localtime(&tm); - strftime(s, TIME_LEN, txt, stm); - *(char **)vp = s; + if (!txt) { + exerror("printf: no time format provided"); + } else { + s = fmtbuf(TIME_LEN); + stm = localtime(&tm); + strftime(s, TIME_LEN, txt, stm); + *(char **)vp = s; + } dp->fmt = 's'; dp->size = -1; break; -- 2.40.0