From 1ad63a7a37a6e845a3655a4e0eb599f716f5761f Mon Sep 17 00:00:00 2001 From: Andrew Wood Date: Sun, 3 Sep 2023 18:18:17 +0100 Subject: [PATCH] Address warnings raised by splint. --- src/pv/elapsedtime.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/pv/elapsedtime.c b/src/pv/elapsedtime.c index 0c49af3..95362f0 100644 --- a/src/pv/elapsedtime.c +++ b/src/pv/elapsedtime.c @@ -25,10 +25,14 @@ */ void pv_elapsedtime_read(struct timespec *return_time) { + /*@-unrecog@*/ /* splint doesn't know clock_gettime */ if (0 != clock_gettime(CLOCK_MONOTONIC, return_time)) { fprintf(stderr, "%s: %s: %s\n", PACKAGE_NAME, "clock_gettime", strerror(errno)); + /*@-exitarg@*/ /* we explicitly want a special exit status */ exit(16); + /*@+exitarg@*/ } + /*@+unrecog@*/ } @@ -72,6 +76,12 @@ int pv_elapsedtime_compare(const struct timespec *first_time, const struct times if ((NULL != first_time) && (NULL == second_time)) return 1; + /* These should never happen, but check just in case. */ + if (NULL == first_time) + return 0; + if (NULL == second_time) + return 0; + /* Check the seconds part, first */ if (first_time->tv_sec < second_time->tv_sec) return -1; @@ -116,8 +126,17 @@ void pv_elapsedtime_add(struct timespec *return_time, const struct timespec *fir seconds += nanoseconds / 1000000000; nanoseconds = nanoseconds % 1000000000; + /*@-type@*/ return_time->tv_sec = seconds; return_time->tv_nsec = nanoseconds; + /*@+type@*/ + + /* + * splint rationale: we know the types are different but should be + * large enough and are relying on the compiler to do the casting + * correctly, since the manual for timespec(3) states the types are + * implementation-defined. + */ } @@ -137,8 +156,10 @@ void pv_elapsedtime_add_nsec(struct timespec *return_time, long long add_nanosec seconds += nanoseconds / 1000000000; nanoseconds = nanoseconds % 1000000000; + /*@-type@*/ /* see above */ return_time->tv_sec = seconds; return_time->tv_nsec = nanoseconds; + /*@+type@*/ } @@ -174,8 +195,10 @@ void pv_elapsedtime_subtract(struct timespec *return_time, const struct timespec nanoseconds = 1000000000 + nanoseconds; } + /*@-type@*/ /* see above */ return_time->tv_sec = seconds; return_time->tv_nsec = nanoseconds; + /*@+type@*/ }