Resolves: RHEL-108555,RHEL-108568,RHEL-108576,RHEL-108584,RHEL-108596,RHEL-108598,RHEL-109096,RHEL-109488,RHEL-111065,RHEL-31756,RHEL-50103
116 lines
3.3 KiB
Diff
116 lines
3.3 KiB
Diff
From 23f6608ffa05ce80ebfbca9a28369ff858e9d42e Mon Sep 17 00:00:00 2001
|
|
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
|
Date: Tue, 14 Feb 2023 02:06:13 +0900
|
|
Subject: [PATCH] time-util: add assertions
|
|
|
|
(cherry picked from commit dff3bddc5416834d42cc682cb544732a4b91db3b)
|
|
|
|
Related: RHEL-109488
|
|
---
|
|
src/basic/time-util.c | 25 +++++++++++++++++++++++++
|
|
1 file changed, 25 insertions(+)
|
|
|
|
diff --git a/src/basic/time-util.c b/src/basic/time-util.c
|
|
index 7dbd3af20a..ac28dc9be6 100644
|
|
--- a/src/basic/time-util.c
|
|
+++ b/src/basic/time-util.c
|
|
@@ -172,6 +172,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;
|
|
@@ -184,6 +186,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) {
|
|
|
|
@@ -421,6 +424,8 @@ char *format_timestamp_relative(char *buf, size_t l, usec_t t) {
|
|
const char *s;
|
|
usec_t n, d;
|
|
|
|
+ assert(buf);
|
|
+
|
|
if (!timestamp_is_set(t))
|
|
return NULL;
|
|
|
|
@@ -902,6 +907,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;
|
|
@@ -991,6 +998,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;
|
|
|
|
@@ -1119,6 +1129,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;
|
|
@@ -1167,6 +1180,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;
|
|
|
|
@@ -1320,6 +1336,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;
|
|
@@ -1477,6 +1495,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 */
|
|
@@ -1506,10 +1526,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);
|
|
}
|
|
|