From bab8757bc9e0b64883c8eeaa9ce5bd1909bbdcd4 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Thu, 26 Feb 2015 14:28:33 -0500 Subject: Pre-release splint/cppcheck/coverity cleanup. All regression tests pass. --- ntpshmread.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'ntpshmread.c') diff --git a/ntpshmread.c b/ntpshmread.c index 5d39dad6..880ef542 100644 --- a/ntpshmread.c +++ b/ntpshmread.c @@ -12,16 +12,19 @@ #include #include #include -#include #include #include +#ifndef S_SPLINT_S +#include +#endif /* S_SPLINT_S*/ #include "ntpshm.h" #include "compiler.h" -struct shmTime *shm_get(const int unit, const bool create, const bool forall) +struct shmTime /*@null@*/ *shm_get(const int unit, const bool create, const bool forall) /* initialize an initial segment */ { + /*@-mustfreefresh@*/ struct shmTime *p = NULL; int shmid; @@ -29,7 +32,7 @@ struct shmTime *shm_get(const int unit, const bool create, const bool forall) * Big units will give non-ascii but that's OK * as long as everybody does it the same way. */ - shmid = shmget(NTPD_BASE + unit, sizeof(struct shmTime), + shmid = shmget((key_t)(NTPD_BASE + unit), sizeof(struct shmTime), (create ? IPC_CREAT : 0) | (forall ? 0666 : 0600)); if (shmid == -1) { /* error */ return NULL; @@ -39,19 +42,22 @@ struct shmTime *shm_get(const int unit, const bool create, const bool forall) return NULL; } return p; + /*@+mustfreefresh@*/ } +/*@-statictrans@*/ char *shm_name(const int unit) /* return the name of a specified segment */ { static char name[5] = "NTP\0"; - name[3] = '0' + (char)unit; + /*@i2@*/name[3] = '0' + (char)unit; return name; } +/*@+statictrans@*/ -enum segstat_t shm_query(struct shmTime *shm_in, struct shm_stat_t *shm_stat) +enum segstat_t shm_query(/*@null@*/struct shmTime *shm_in, /*@out@*/struct shm_stat_t *shm_stat) /* try to grab a sample from the specified SHM segment */ { volatile struct shmTime shmcopy, *shm = shm_in; @@ -64,6 +70,7 @@ enum segstat_t shm_query(struct shmTime *shm_in, struct shm_stat_t *shm_stat) return NO_SEGMENT; } + /*@-type@*//* splint is confused about struct timespec */ shm_stat->tvc.tv_sec = shm_stat->tvc.tv_nsec = 0; clock_gettime(CLOCK_REALTIME, &shm_stat->tvc); @@ -155,6 +162,7 @@ enum segstat_t shm_query(struct shmTime *shm_in, struct shm_stat_t *shm_stat) shm_stat->status = BAD_MODE; break; } + /*@-type@*/ /* * leap field is not a leap offset but a leap notification code. -- cgit v1.2.1