summaryrefslogtreecommitdiffstats
path: root/lib/strformat.c
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@opensourcerouting.org>2022-04-28 12:23:16 +0200
committerDavid Lamparter <equinox@opensourcerouting.org>2022-04-28 15:51:00 +0200
commit782fe5e4500225eddc3cc989ea327a49863fbe66 (patch)
tree8ce12f7adde727edb81010983a688a060d980949 /lib/strformat.c
parentMerge pull request #11031 from AbhishekNR/v6_multicast (diff)
downloadfrr-782fe5e4500225eddc3cc989ea327a49863fbe66.tar.xz
frr-782fe5e4500225eddc3cc989ea327a49863fbe66.zip
lib: format NULL timevals correctly
Passing NULL for a `%pTVMs` would result in `(null)Ms`, i.e. the `Ms` flags not eaten up. Change to eat those up, and print `-` instead for NULL times. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'lib/strformat.c')
-rw-r--r--lib/strformat.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/strformat.c b/lib/strformat.c
index a420ba553..d941a7f04 100644
--- a/lib/strformat.c
+++ b/lib/strformat.c
@@ -361,6 +361,8 @@ static ssize_t printfrr_abstime(struct fbuf *buf, struct printfrr_eargs *ea,
if (flags & TIMEFMT_SKIP)
return 0;
+ if (!ts)
+ return bputch(buf, '-');
if (flags & TIMEFMT_REALTIME)
*real_ts = *ts;
@@ -452,6 +454,8 @@ static ssize_t printfrr_reltime(struct fbuf *buf, struct printfrr_eargs *ea,
if (flags & TIMEFMT_SKIP)
return 0;
+ if (!ts)
+ return bputch(buf, '-');
if (flags & TIMEFMT_ABSOLUTE) {
struct timespec anchor[1];
@@ -561,8 +565,6 @@ static ssize_t printfrr_ts(struct fbuf *buf, struct printfrr_eargs *ea,
{
const struct timespec *ts = vptr;
- if (!ts)
- return bputs(buf, "(null)");
return printfrr_time(buf, ea, ts, 0);
}
@@ -574,7 +576,7 @@ static ssize_t printfrr_tv(struct fbuf *buf, struct printfrr_eargs *ea,
struct timespec ts;
if (!tv)
- return bputs(buf, "(null)");
+ return printfrr_time(buf, ea, NULL, 0);
ts.tv_sec = tv->tv_sec;
ts.tv_nsec = tv->tv_usec * 1000;
@@ -589,7 +591,7 @@ static ssize_t printfrr_tt(struct fbuf *buf, struct printfrr_eargs *ea,
struct timespec ts;
if (!tt)
- return bputs(buf, "(null)");
+ return printfrr_time(buf, ea, NULL, TIMEFMT_SECONDS);
ts.tv_sec = *tt;
ts.tv_nsec = 0;