diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-02-14 02:06:13 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-02-24 08:55:27 +0900 |
commit | dff3bddc5416834d42cc682cb544732a4b91db3b (patch) | |
tree | 195f7054e16a3a361e54efb923ac8c74decadba3 /src/basic/time-util.c | |
parent | cf98b66d1ad0ff0e9ee0444861069ebade038dbb (diff) | |
download | systemd-dff3bddc5416834d42cc682cb544732a4b91db3b.tar.gz |
time-util: add assertions
Diffstat (limited to 'src/basic/time-util.c')
-rw-r--r-- | src/basic/time-util.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/basic/time-util.c b/src/basic/time-util.c index 7f5605953f..f563b8560c 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -171,6 +171,8 @@ dual_timestamp* dual_timestamp_from_monotonic(dual_timestamp *ts, usec_t u) { dual_timestamp* dual_timestamp_from_boottime(dual_timestamp *ts, usec_t u) { usec_t nowm; + assert(ts); + if (u == USEC_INFINITY) { ts->realtime = ts->monotonic = USEC_INFINITY; return ts; @@ -183,6 +185,7 @@ dual_timestamp* dual_timestamp_from_boottime(dual_timestamp *ts, usec_t u) { } usec_t triple_timestamp_by_clock(triple_timestamp *ts, clockid_t clock) { + assert(ts); switch (clock) { @@ -422,6 +425,8 @@ char* format_timestamp_relative_full(char *buf, size_t l, usec_t t, bool implici const char *s; usec_t n, d; + assert(buf); + if (!timestamp_is_set(t)) return NULL; @@ -903,6 +908,8 @@ int parse_timestamp(const char *t, usec_t *ret) { ParseTimestampResult *shared, tmp; int r; + assert(t); + last_space = strrchr(t, ' '); if (last_space != NULL && timezone_is_valid(last_space + 1, LOG_DEBUG)) tz = last_space + 1; @@ -992,6 +999,9 @@ static const char* extract_multiplier(const char *p, usec_t *ret) { { "µs", 1ULL }, }; + assert(p); + assert(ret); + for (size_t i = 0; i < ELEMENTSOF(table); i++) { char *e; @@ -1120,6 +1130,9 @@ int parse_sec_fix_0(const char *t, usec_t *ret) { } int parse_sec_def_infinity(const char *t, usec_t *ret) { + assert(t); + assert(ret); + t += strspn(t, WHITESPACE); if (isempty(t)) { *ret = USEC_INFINITY; @@ -1168,6 +1181,9 @@ static const char* extract_nsec_multiplier(const char *p, nsec_t *ret) { }; size_t i; + assert(p); + assert(ret); + for (i = 0; i < ELEMENTSOF(table); i++) { char *e; @@ -1321,6 +1337,8 @@ static int get_timezones_from_tzdata_zi(char ***ret) { _cleanup_strv_free_ char **zones = NULL; int r; + assert(ret); + f = fopen("/usr/share/zoneinfo/tzdata.zi", "re"); if (!f) return -errno; @@ -1478,6 +1496,8 @@ int get_timezone(char **ret) { char *z; int r; + assert(ret); + r = readlink_malloc("/etc/localtime", &t); if (r == -ENOENT) { /* If the symlink does not exist, assume "UTC", like glibc does */ @@ -1507,10 +1527,15 @@ int get_timezone(char **ret) { } time_t mktime_or_timegm(struct tm *tm, bool utc) { + assert(tm); + return utc ? timegm(tm) : mktime(tm); } struct tm *localtime_or_gmtime_r(const time_t *t, struct tm *tm, bool utc) { + assert(t); + assert(tm); + return utc ? gmtime_r(t, tm) : localtime_r(t, tm); } |