From 5b7c5fd4d856ad222dc51d79f8cf972730e48a54 Mon Sep 17 00:00:00 2001 From: haozi007 Date: Mon, 17 Oct 2022 14:31:39 +0800 Subject: [PATCH 17/43] add static for unexport function 1. add static for inner function; 2. add check for aguments; 3. remove same code; Signed-off-by: haozi007 --- src/utils/cutils/utils_timestamp.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/utils/cutils/utils_timestamp.c b/src/utils/cutils/utils_timestamp.c index c490c00e..85551d51 100644 --- a/src/utils/cutils/utils_timestamp.c +++ b/src/utils/cutils/utils_timestamp.c @@ -39,7 +39,7 @@ bool unix_nanos_to_timestamp(int64_t nanos, types_timestamp_t *timestamp) return true; } -int types_timestamp_cmp_check(const types_timestamp_t *t1, const types_timestamp_t *t2) +static int types_timestamp_cmp_check(const types_timestamp_t *t1, const types_timestamp_t *t2) { if (t1 == NULL && t2 == NULL) { return 0; @@ -54,7 +54,7 @@ int types_timestamp_cmp_check(const types_timestamp_t *t1, const types_timestamp return 2; } -int types_timestamp_cmp_nanos(const types_timestamp_t *t1, const types_timestamp_t *t2) +static int types_timestamp_cmp_nanos(const types_timestamp_t *t1, const types_timestamp_t *t2) { if (t1->has_nanos && t2->has_nanos) { if (t1->nanos > t2->nanos) { @@ -147,7 +147,7 @@ bool util_get_timestamp(const char *str_time, types_timestamp_t *timestamp) return true; } -bool get_time_buffer_help(const types_timestamp_t *timestamp, char *timebuffer, size_t maxsize, bool local_utc) +static bool get_time_buffer_help(const types_timestamp_t *timestamp, char *timebuffer, size_t maxsize, bool local_utc) { int nret = 0; int tm_zone_hour = 0; @@ -222,6 +222,11 @@ bool util_get_now_time_stamp(types_timestamp_t *timestamp) int err = 0; struct timespec ts; + if (timestamp == NULL) { + ERROR("Invalid arguments"); + return false; + } + err = clock_gettime(CLOCK_REALTIME, &ts); if (err != 0) { ERROR("failed to get time"); @@ -586,10 +591,11 @@ static bool get_tm_zone_from_str(const char *str, struct tm *tm, int32_t *nanos, char *tmstr = NULL; char *zp = NULL; char *zonestr = NULL; + bool ret = false; if (hasnil(str, tm, nanos, tz)) { ERROR("Get tm and timezone from str input error"); - goto err_out; + return false; } tmstr = util_strdup_s(str); @@ -610,15 +616,12 @@ static bool get_tm_zone_from_str(const char *str, struct tm *tm, int32_t *nanos, ERROR("init tz failed"); goto err_out; } - - free(tmstr); - free(zonestr); - return true; + ret = true; err_out: free(tmstr); free(zonestr); - return false; + return ret; } static int64_t get_minmus_time(struct tm *tm1, struct tm *tm2) -- 2.25.1