diff options
-rw-r--r-- | SConstruct | 5 | ||||
-rw-r--r-- | contrib/motosend.c | 24 | ||||
-rw-r--r-- | gpsd.c | 4 | ||||
-rw-r--r-- | gpsmon.c | 3 | ||||
-rw-r--r-- | gpsutils.c | 2 | ||||
-rw-r--r-- | ppsthread.c | 49 |
6 files changed, 36 insertions, 51 deletions
@@ -1440,7 +1440,7 @@ def Utility(target, source, action): Utility("cppcheck", ["gpsd.h", "packet_names.h"], "cppcheck -U__UNUSED__ -UUSE_QT -U__COVERITY__ -U__future__ -ULIMITED_MAX_CLIENTS -ULIMITED_MAX_DEVICES -UAF_UNSPEC -UINADDR_ANY -UFIXED_PORT_SPEED -UFIXED_STOP_BITS -U_WIN32 -U__CYGWIN__ -UPATH_MAX -UHAVE_STRLCAT -UHAVE_STRLCPY -UIPTOS_LOWDELAY -UIPV6_TCLASS -UTCP_NODELAY -UTIOCMIWAIT --template gcc --enable=all --inline-suppr --suppress='*:driver_proto.c' --force $SRCDIR") -# Experimental check with clang analyzer +# Check with clang analyzer Utility("scan-build", ["gpsd.h", "packet_names.h"], "scan-build scons") @@ -1469,7 +1469,8 @@ Utility("deheader", generated_sources, [ # Perform all local code-sanity checks (but not the Coverity scan). audit = env.Alias('audit', - ['cppcheck', + ['scan-build', + 'cppcheck', 'pylint', 'xmllint', 'valgrind-audit', diff --git a/contrib/motosend.c b/contrib/motosend.c index 05c73530..30731588 100644 --- a/contrib/motosend.c +++ b/contrib/motosend.c @@ -168,19 +168,21 @@ char *gpsd_hexdump(char *binbuf, size_t binbuflen) int gpsd_hexpack(char *src, char *dst, int len) { - int i, l, k; + int i, l; - l = (int)(strlen(src) / 2); - if ((l < 1) || (l > len)) - return -1; + l = (int)(strlen(src) / 2); + if ((l < 1) || (l > len)) + return -1; - bzero(dst, len); - for (i = 0; i < l; i++) - if ((k = hex2bin(src+i*2)) != -1) - dst[i] = (char)(k & 0xff); - else - return -1; - return l; + bzero(dst, len); + for (i = 0; i < l; i++) { + int k; + if ((k = hex2bin(src+i*2)) != -1) + dst[i] = (char)(k & 0xff); + else + return -1; + } + return l; } int hex2bin(char *s) @@ -573,6 +573,7 @@ static ssize_t throttled_write(struct subscriber_t *sub, char *buf, gpsd_log(&context.errout, LOG_CLIENT, "=> client(%d): %s\n", sub_index(sub), buf); else { +#ifndef __clang_analyzer__ char *cp, buf2[MAX_PACKET_LENGTH * 3]; buf2[0] = '\0'; for (cp = buf; cp < buf + len; cp++) @@ -580,6 +581,7 @@ static ssize_t throttled_write(struct subscriber_t *sub, char *buf, "%02x", (unsigned int)(*cp & 0xff)); gpsd_log(&context.errout, LOG_CLIENT, "=> client(%d): =%s\n", sub_index(sub), buf2); +#endif /* __clang_analyzer__ */ } } @@ -966,6 +968,7 @@ static void set_serial(struct gps_device_t *device, char parity = device->gpsdata.dev.parity; int wordsize = 8; +#ifndef __clang_analyzer__ while (isspace((unsigned char) *modestring)) modestring++; if (*modestring && strchr("78", *modestring) != NULL) { @@ -978,6 +981,7 @@ static void set_serial(struct gps_device_t *device, stopbits = (unsigned int)(*modestring - '0'); } } +#endif /* __clang_analyzer__ */ gpsd_log(&context.errout, LOG_PROG, "set_serial(%s,%u,%s) %c%d\n", @@ -1317,7 +1317,10 @@ int main(int argc, char **argv) } FD_ZERO(&all_fds); +#ifndef __clang_analyzer__ FD_SET(0, &all_fds); /* accept keystroke inputs */ +#endif /* __clang_analyzer__ */ + FD_SET(session.gpsdata.gps_fd, &all_fds); if (session.gpsdata.gps_fd > maxfd) @@ -333,6 +333,7 @@ time_t mkgmtime(register struct tm * t) timestamp_t iso8601_to_unix(char *isotime) /* ISO8601 UTC to Unix UTC, no leapsecond correction. */ { +#ifndef __clang_analyzer__ #ifndef USE_QT char *dp = NULL; double usec; @@ -362,6 +363,7 @@ timestamp_t iso8601_to_unix(char *isotime) usec = sl[1].toInt() / pow(10., (double)sl[1].size()); return (timestamp_t)(d.toTime_t() + usec); #endif +#endif /* __clang_analyzer__ */ } /* *INDENT-OFF* */ diff --git a/ppsthread.c b/ppsthread.c index 744cf090..3336ec44 100644 --- a/ppsthread.c +++ b/ppsthread.c @@ -54,22 +54,9 @@ #include <limits.h> #include <errno.h> #include <math.h> -#ifdef S_SPLINT_S -/*@-type@*/ -int strerror_r(int errnum, char *buf, size_t buflen); -/*@+type@*/ -/*@-matchfields@*/ -struct timespec - { - time_t tv_sec; /* Seconds. */ - long tv_nsec; /* Nanoseconds. */ - }; -/*@+matchfields@*/ -#else #include <pthread.h> #include <sys/socket.h> #include <unistd.h> -#endif /* S_SPLINT_S */ #include "gpsd_config.h" #include "timespec_str.h" @@ -158,18 +145,14 @@ static inline void TS_NORM( struct timespec *ts) TS_NORM( r ); \ } while (0) -/*@-type@*/ static pthread_mutex_t ppslast_mutex = PTHREAD_MUTEX_INITIALIZER; -/*@+type@*/ #if defined(HAVE_SYS_TIMEPPS_H) static int init_kernel_pps(volatile struct pps_thread_t *pps_thread) /* return handle for kernel pps, or -1; requires root privileges */ { -#ifndef S_SPLINT_S pps_params_t pp; int pps_caps; -#endif /* S_SPLINT_S */ int ret; #ifdef __linux__ /* These variables are only needed by Linux to find /dev/ppsN. */ @@ -184,8 +167,10 @@ static int init_kernel_pps(volatile struct pps_thread_t *pps_thread) * This next code block abuses "ret" by storing the filedescriptor * to use for RFC2783 calls. */ +#ifndef __clang_analyzer__ ret = -1; /* this ret will not be unneeded when the 'else' part * of the followinng ifdef becomes an #elif */ +#endif /* __clang_analyzer__ */ #ifdef __linux__ /* * Some Linuxes, like the RasbPi's, have PPS devices preexisting. @@ -292,7 +277,6 @@ static int init_kernel_pps(volatile struct pps_thread_t *pps_thread) pps_thread->devicename, path, ret); -#ifndef S_SPLINT_S /* RFC 2783 implies the time_pps_setcap() needs priviledges * * keep root a tad longer just in case */ if ( 0 > time_pps_create(ret, (pps_handle_t *)&pps_thread->kernelpps_handle )) { @@ -369,7 +353,6 @@ static int init_kernel_pps(volatile struct pps_thread_t *pps_thread) (void)time_pps_destroy(pps_thread->kernelpps_handle); return -1; } -#endif /* S_SPLINT_S */ return 0; } #endif /* defined(HAVE_SYS_TIMEPPS_H) */ @@ -497,10 +480,8 @@ static int get_edge_rfc2783( volatile struct pps_thread_t *thread_context, int *edge, volatile struct timedelta_t *last_fixtime) { -#ifndef S_SPLINT_S pps_info_t pi; char ts_str1[TIMESPEC_LEN], ts_str2[TIMESPEC_LEN]; -#endif /* S_SPLINT_S */ struct timespec kernelpps_tv; if ( pps_canwait ) { @@ -528,8 +509,7 @@ static int get_edge_rfc2783( volatile struct pps_thread_t *thread_context, */ memset( (void *)&kernelpps_tv, 0, sizeof(kernelpps_tv)); } -#ifndef S_SPLINT_S - memset( (void *)&pi, 0, sizeof(pi)); /* paranoiia, and to shutup splint */ + memset( (void *)&pi, 0, sizeof(pi)); /* paranoia */ if ( 0 > time_pps_fetch(thread_context->kernelpps_handle, PPS_TSFMT_TSPEC , &pi, &kernelpps_tv)) { @@ -544,7 +524,6 @@ static int get_edge_rfc2783( volatile struct pps_thread_t *thread_context, } return 0; } -#endif /* S_SPLINT_S */ if ( pps_canwait ) { int pthread_err; /* return code from pthread functions */ @@ -573,7 +552,6 @@ static int get_edge_rfc2783( volatile struct pps_thread_t *thread_context, } -#ifndef S_SPLINT_S // find the last edge if ( pi.assert_timestamp.tv_sec > pi.clear_timestamp.tv_sec ) { /* assert 1 sec or more after than clear */ @@ -623,13 +601,12 @@ static int get_edge_rfc2783( volatile struct pps_thread_t *thread_context, ts_str2, (unsigned long) pi.clear_sequence, *edge ? "assert" : "clear"); -#endif /* S_SPLINT_S */ return 0; } #endif /* defined(HAVE_SYS_TIMEPPS_H) */ -static /*@null@*/ void *gpsd_ppsmonitor(void *arg) +static void *gpsd_ppsmonitor(void *arg) { char ts_str1[TIMESPEC_LEN], ts_str2[TIMESPEC_LEN]; volatile struct pps_thread_t *thread_context = (struct pps_thread_t *)arg; @@ -661,9 +638,7 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) #endif /* TIOCMIWAIT */ #if defined(HAVE_SYS_TIMEPPS_H) -#ifndef S_SPLINT_S int pps_caps; -#endif /* S_SPLINT_S */ long cycle_kpps = 0, duration_kpps = 0; /* kpps_pulse stores the time of the last two edges */ struct timespec pulse_kpps[2] = { {0, 0}, {0, 0} }; @@ -684,7 +659,6 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) } /* if no TIOCMIWAIT, we hope to have PPS_CANWAIT */ -#ifndef S_SPLINT_S #if defined(HAVE_SYS_TIMEPPS_H) /* get RFC2783 features supported */ pps_caps = 0; @@ -713,7 +687,6 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) pps_canwait = true; } #endif /* HAVE_SYS_TIMEPPS_H */ -#endif /* S_SPLINT_S */ if ( not_a_tty && !pps_canwait ) { /* for now, no way to wait for an edge, in the future maybe figure out @@ -771,7 +744,9 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) pulse_tio[edge_tio] = clock_ts_tio; /* use this data */ +#ifndef __clang_analyzer__ ok = true; +#endif /* __clang_analyzer__ */ clock_ts = clock_ts_tio; state = edge_tio; edge = edge_tio; @@ -840,7 +815,9 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) pulse_kpps[edge_kpps] = clock_ts_kpps; pulse_kpps[edge_kpps ? 0 : 1] = prev_clock_ts; /* sanity checks are later */ +#ifndef __clang_analyzer__ log = "KPPS"; +#endif /* __clang_analyzer__ */ /* use this data */ state = edge_kpps; @@ -999,9 +976,7 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) /* probably should log computed offset just for grins here */ ok = false; log = "missing last_fixtime\n"; - /*@+longintegral@*/ } else if ( ok && last_second_used >= last_fixtime.real.tv_sec ) { - /*@-longintegral@*/ /* uh, oh, this second already handled */ ok = false; log = "this second already handled\n"; @@ -1016,7 +991,7 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) struct timespec delay; /* delay as a printable string */ char delay_str[TIMESPEC_LEN]; - /*@observer@*/ char *log1 = ""; + char *log1 = ""; /* ppstimes.real is the time we think the pulse represents */ struct timedelta_t ppstimes; thread_context->log_hook(thread_context, THREAD_RAW, @@ -1112,7 +1087,7 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) thread_context->log_hook(thread_context, THREAD_PROG, "PPS:%s descriptor cleaned up\n", thread_context->devicename); - /*@i1@*/(void)time_pps_destroy(thread_context->kernelpps_handle); + (void)time_pps_destroy(thread_context->kernelpps_handle); } #endif if (thread_context->wrap_hook != NULL) @@ -1148,7 +1123,7 @@ void pps_thread_activate(volatile struct pps_thread_t *pps_thread) } memset( &pt, 0, sizeof(pt)); - /*@i1@*/retval = pthread_create(&pt, NULL, gpsd_ppsmonitor, (void *)pps_thread); + retval = pthread_create(&pt, NULL, gpsd_ppsmonitor, (void *)pps_thread); pps_thread->log_hook(pps_thread, THREAD_PROG, "PPS:%s thread %s\n", pps_thread->devicename, (retval==0) ? "launched" : "FAILED"); @@ -1157,9 +1132,7 @@ void pps_thread_activate(volatile struct pps_thread_t *pps_thread) void pps_thread_deactivate(volatile struct pps_thread_t *pps_thread) /* cleanly terminate PPS thread */ { - /*@-mustfreeonly@*/ pps_thread->report_hook = NULL; - /*@+mustfreeonly@*/ pps_thread->pps_hook = NULL; } |