Skip to content

Commit

Permalink
Merge pull request #11118 from opensourcerouting/time-fmt-nulls
Browse files Browse the repository at this point in the history
lib: format NULL timevals correctly
  • Loading branch information
donaldsharp authored Apr 29, 2022
2 parents 46a3bfa + 782fe5e commit 9ad0725
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/strformat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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);
}

Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 9ad0725

Please sign in to comment.