From: Lennart Poettering Date: Fri, 20 Jan 2023 12:46:40 +0000 (+0100) Subject: time-util: simplify formatting of UNIX timestamps X-Git-Tag: v253-rc1~52^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=61d03c54167acfad15f3ba89f082d55030bd3aea;p=thirdparty%2Fsystemd.git time-util: simplify formatting of UNIX timestamps --- diff --git a/src/basic/time-util.c b/src/basic/time-util.c index 081fa010040..dcafad48828 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -311,7 +311,6 @@ char *format_timestamp_style( bool utc, us; time_t sec; size_t n; - int r; assert(buf); assert(style >= 0); @@ -321,11 +320,10 @@ char *format_timestamp_style( return NULL; /* Timestamp is unset */ if (style == TIMESTAMP_UNIX) { - r = snprintf(buf, l, "@" USEC_FMT, t / USEC_PER_SEC); /* round down µs → s */ - if (r < 0 || (size_t) r >= l) - return NULL; /* Doesn't fit */ + if (l < (size_t) (1 + 1 + 1)) + return NULL; /* not enough space for even the shortest of forms */ - return buf; + return snprintf_ok(buf, l, "@" USEC_FMT, t / USEC_PER_SEC); /* round down µs → s */ } utc = IN_SET(style, TIMESTAMP_UTC, TIMESTAMP_US_UTC);