summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2013-04-30 23:04:53 -0400
committerEric S. Raymond <esr@thyrsus.com>2013-04-30 23:05:37 -0400
commit321c7710c3f3a17d56e9e5eede9aebadbaf16e3e (patch)
treefae8712111ede1cd948e8846a3bbdafeb8dfd45a
parent5aa7ce8d00de15c832ab90113ef5b08221746e7f (diff)
downloadgpsd-321c7710c3f3a17d56e9e5eede9aebadbaf16e3e.tar.gz
Fix static-checker warnings. All regression tests pass.
cppchecker now finds variables that could have reduced scope; that's most of these.
-rw-r--r--driver_evermore.c13
-rw-r--r--driver_geostar.c3
-rw-r--r--driver_sirf.c2
-rw-r--r--driver_tsip.c5
-rw-r--r--drivers.c11
-rw-r--r--gpsctl.c2
-rw-r--r--gpsd.c2
-rw-r--r--gpsd_json.c24
-rw-r--r--gpsmon.c2
-rw-r--r--gpspipe.c19
-rw-r--r--lcdgps.c3
-rw-r--r--libgps_core.c11
-rw-r--r--net_dgpsip.c2
-rw-r--r--timebase.c3
14 files changed, 54 insertions, 48 deletions
diff --git a/driver_evermore.c b/driver_evermore.c
index 69de6ee9..808e1197 100644
--- a/driver_evermore.c
+++ b/driver_evermore.c
@@ -581,17 +581,16 @@ static bool evermore_rate_switcher(struct gps_device_t *session, double rate)
/* change the sample rate of the GPS */
{
/*@ +charint @*/
- unsigned char evrm_rate_config[] = {
- 0x84, /* 1: msg ID, Operating Mode Configuration */
- 0x02, /* 2: normal mode with 1PPS */
- 0x00, /* 3: navigation update rate */
- 0x00, /* 4: RF/GPSBBP On Time */
- };
-
if (rate < 1 || rate > 10) {
gpsd_report(LOG_ERROR, "valid rate range is 1-10.\n");
return false;
} else {
+ unsigned char evrm_rate_config[] = {
+ 0x84, /* 1: msg ID, Operating Mode Configuration */
+ 0x02, /* 2: normal mode with 1PPS */
+ 0x00, /* 3: navigation update rate */
+ 0x00, /* 4: RF/GPSBBP On Time */
+ };
evrm_rate_config[2] = (unsigned char)trunc(rate);
return (evermore_control_send(session, (char *)evrm_rate_config,
sizeof(evrm_rate_config)) != -1);
diff --git a/driver_geostar.c b/driver_geostar.c
index 47150517..e18e803b 100644
--- a/driver_geostar.c
+++ b/driver_geostar.c
@@ -538,10 +538,9 @@ static bool geostar_speed_switch(struct gps_device_t *session,
static void geostar_mode(struct gps_device_t *session, int mode)
{
- unsigned char buf[1 * 4];
-
/*@-shiftimplementation@*/
if (mode == MODE_NMEA) {
+ unsigned char buf[1 * 4];
/* Switch to NMEA mode */
putbe32(buf, 0, 1);
(void)geostar_write(session, 0x46, buf, 1);
diff --git a/driver_sirf.c b/driver_sirf.c
index ce07052a..fbb6a4b8 100644
--- a/driver_sirf.c
+++ b/driver_sirf.c
@@ -346,10 +346,10 @@ static bool sirf_to_nmea(struct gps_device_t *session, speed_t speed)
static void sirfbin_mode(struct gps_device_t *session, int mode)
{
- char parity = '0';
if (mode == MODE_NMEA) {
(void)sirf_to_nmea(session, session->gpsdata.dev.baudrate);
} else if (mode == MODE_BINARY) {
+ char parity = '0';
switch (session->gpsdata.dev.parity) {
default:
case 'N':
diff --git a/driver_tsip.c b/driver_tsip.c
index 3c99138a..ea4250bb 100644
--- a/driver_tsip.c
+++ b/driver_tsip.c
@@ -1067,11 +1067,10 @@ static bool tsip_speed_switch(struct gps_device_t *session,
static void tsip_mode(struct gps_device_t *session, int mode)
{
- unsigned char buf[16];
-
if (mode == MODE_NMEA) {
- /* First turn on the NMEA messages we want */
+ unsigned char buf[16];
+ /* First turn on the NMEA messages we want */
putbyte(buf, 0, 0x00); /* subcode 0 */
putbyte(buf, 1, 0x01); /* 1-second fix interval */
putbyte(buf, 2, 0x00); /* Reserved */
diff --git a/drivers.c b/drivers.c
index e6632906..9d350812 100644
--- a/drivers.c
+++ b/drivers.c
@@ -1075,8 +1075,6 @@ static const struct gps_type_t garmintxt = {
static gps_mask_t processMTK3301(struct gps_device_t *session)
{
- const char *mtk_reasons[4] =
- { "Invalid", "Unsupported", "Valid but Failed", "Valid success" };
gps_mask_t mask;
/* try a straight NMEA parse, this will set up fields */
@@ -1098,9 +1096,16 @@ static gps_mask_t processMTK3301(struct gps_device_t *session)
reason = atoi(session->driver.nmea.field[2]);
if (atoi(session->driver.nmea.field[1]) == -1)
gpsd_report(LOG_WARN, "MTK NACK: unknown sentence\n");
- else if (reason < 3)
+ else if (reason < 3) {
+ const char *mtk_reasons[] = {
+ "Invalid",
+ "Unsupported",
+ "Valid but Failed",
+ "Valid success"
+ };
gpsd_report(LOG_WARN, "MTK NACK: %s, reason: %s\n", session->driver.nmea.field[1],
mtk_reasons[reason]);
+ }
else
gpsd_report(LOG_WARN, "MTK ACK: %s\n", session->driver.nmea.field[1]);
break;
diff --git a/gpsctl.c b/gpsctl.c
index 111670aa..24a155a5 100644
--- a/gpsctl.c
+++ b/gpsctl.c
@@ -33,8 +33,8 @@ static unsigned int timeout = 8;
void gpsd_report(int errlevel UNUSED, const char *fmt, ... )
/* our version of the logger */
{
- char *err_str;
if (errlevel <= debuglevel) {
+ char *err_str;
va_list ap;
va_start(ap, fmt);
switch ( errlevel ) {
diff --git a/gpsd.c b/gpsd.c
index e71ecb96..ff4435c7 100644
--- a/gpsd.c
+++ b/gpsd.c
@@ -2273,7 +2273,6 @@ int main(int argc, char *argv[])
for (i = 0; i < AFCOUNT; i++) {
if (msocks[i] >= 0 && FD_ISSET(msocks[i], &rfds)) {
socklen_t alen = (socklen_t) sizeof(fsin);
- char *c_ip;
/*@+matchanyintegral@*/
socket_t ssock =
accept(msocks[i], (struct sockaddr *)&fsin, &alen);
@@ -2285,6 +2284,7 @@ int main(int argc, char *argv[])
struct subscriber_t *client = NULL;
int opts = fcntl(ssock, F_GETFL);
static struct linger linger = { 1, RELEASE_TIMEOUT };
+ char *c_ip;
if (opts >= 0)
(void)fcntl(ssock, F_SETFL, opts | O_NONBLOCK);
diff --git a/gpsd_json.c b/gpsd_json.c
index 6076d4b0..eb0fb09b 100644
--- a/gpsd_json.c
+++ b/gpsd_json.c
@@ -357,12 +357,12 @@ void json_sky_dump(const struct gps_data_t *datap,
void json_device_dump(const struct gps_device_t *device,
/*@out@*/ char *reply, size_t replylen)
{
- char buf1[JSON_VAL_MAX * 2 + 1];
struct classmap_t *cmp;
(void)strlcpy(reply, "{\"class\":\"DEVICE\",\"path\":\"", replylen);
(void)strlcat(reply, device->gpsdata.dev.path, replylen);
(void)strlcat(reply, "\",", replylen);
if (device->gpsdata.online > 0) {
+ char buf1[JSON_VAL_MAX * 2 + 1];
(void)snprintf(reply + strlen(reply), replylen - strlen(reply),
"\"activated\":\"%s\",",
unix_to_iso8601(device->gpsdata.online, buf1, sizeof(buf1)));
@@ -445,10 +445,6 @@ void json_subframe_dump(const struct gps_data_t *datap,
const struct subframe_t *subframe = &datap->subframe;
const bool scaled = datap->policy.scaled;
- /* system message is 24 chars, but they could ALL require escaping,
- * like \uXXXX for each char */
- char buf1[25 * 6];
-
(void)snprintf(buf, buflen, "{\"class\":\"SUBFRAME\",\"device\":\"%s\","
"\"tSV\":%u,\"TOW17\":%u,\"frame\":%u,\"scaled\":%s",
datap->dev.path,
@@ -626,15 +622,19 @@ void json_subframe_dump(const struct gps_data_t *datap,
/*@-charint@*/
}
case 55:
- /* JSON is UTF-8. double quote, backslash and
- * control charactores (U+0000 through U+001F).must be
- * escaped. */
- /* system message can be 24 bytes, JSON can escape all
- * chars so up to 24*6 long. */
+ /* JSON is UTF-8. double quote, backslash and
+ * control charactores (U+0000 through U+001F).must be
+ * escaped. */
+ /* system message can be 24 bytes, JSON can escape all
+ * chars so up to 24*6 long. */
+
+ {
+ char buf1[25 * 6];
(void)json_stringify(buf1, sizeof(buf1), subframe->sub4_17.str);
(void)snprintf(buf + len, buflen - len,
- ",\"system_message\":\"%.144s\"", buf1);
- break;
+ ",\"system_message\":\"%.144s\"", buf1);
+ }
+ break;
case 56:
if (scaled) {
(void)snprintf(buf + len, buflen - len,
diff --git a/gpsmon.c b/gpsmon.c
index 36251298..1f421960 100644
--- a/gpsmon.c
+++ b/gpsmon.c
@@ -162,7 +162,6 @@ void gpsd_report(int errlevel, const char *fmt, ...)
/* our version of the logger */
{
char buf[BUFSIZ];
- char buf2[BUFSIZ];
char *err_str;
switch ( errlevel ) {
@@ -200,6 +199,7 @@ void gpsd_report(int errlevel, const char *fmt, ...)
(void)strlcpy(buf, "gpsd:", BUFSIZ);
(void)strncat(buf, err_str, BUFSIZ - strlen(buf) );
if (errlevel <= context.debug && packetwin != NULL) {
+ char buf2[BUFSIZ];
va_list ap;
va_start(ap, fmt);
(void)vsnprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), fmt, ap);
diff --git a/gpspipe.c b/gpspipe.c
index 39134f8f..19ed678e 100644
--- a/gpspipe.c
+++ b/gpspipe.c
@@ -323,21 +323,24 @@ int main(int argc, char **argv)
if (new_line && timestamp) {
char tmstr_u[20]; // time with "usec" resolution
struct timeval now;
- gettimeofday( &now, NULL );
+ struct tm *tmp_now;
- struct tm *tmp_now = localtime(&(now.tv_sec));
+ (void)gettimeofday( &now, NULL );
+ tmp_now = localtime((time_t *)&(now.tv_sec));
(void)strftime(tmstr, sizeof(tmstr), format, tmp_now);
new_line = 0;
switch( option_u ) {
- case 2:
- sprintf(tmstr_u, " %ld.%06ld", now.tv_sec, now.tv_usec);
+ case 2:
+ (void)snprintf(tmstr_u, sizeof(tmstr_u),
+ " %ld.%06ld", now.tv_sec, now.tv_usec);
break;
- case 1:
- sprintf(tmstr_u, ".%06ld", now.tv_usec);
+ case 1:
+ (void)snprintf(tmstr_u, sizeof(tmstr_u),
+ ".%06ld", now.tv_usec);
break;
- default:
- *tmstr_u=0;
+ default:
+ *tmstr_u = '\0';
break;
}
diff --git a/lcdgps.c b/lcdgps.c
index 2bfe7ac1..df560559 100644
--- a/lcdgps.c
+++ b/lcdgps.c
@@ -180,7 +180,7 @@ static enum deg_str_type deg_type = deg_dd;
static void update_lcd(struct gps_data_t *gpsdata)
{
char tmpbuf[255];
- char *s, *gridsquare;
+ char *gridsquare;
/* Get our location in Maidenhead. */
gridsquare = maidenhead(gpsdata->fix.latitude,gpsdata->fix.longitude);
@@ -188,6 +188,7 @@ static void update_lcd(struct gps_data_t *gpsdata)
/* Fill in the latitude and longitude. */
if (gpsdata->fix.mode >= MODE_2D) {
int track;
+ char *s;
s = deg_to_str(deg_type, fabs(gpsdata->fix.latitude));
snprintf(tmpbuf, 254, "widget_set gpsd one 1 1 {Lat: %s %c}\n", s, (gpsdata->fix.latitude < 0) ? 'S' : 'N');
diff --git a/libgps_core.c b/libgps_core.c
index 1c68dbb3..3d0c57e6 100644
--- a/libgps_core.c
+++ b/libgps_core.c
@@ -274,9 +274,6 @@ extern const char /*@observer@*/ *gps_errstr(const int err)
#ifdef LIBGPS_DEBUG
void libgps_dump_state(struct gps_data_t *collect)
{
- const char *status_values[] = { "NO_FIX", "FIX", "DGPS_FIX" };
- const char *mode_values[] = { "", "NO_FIX", "MODE_2D", "MODE_3D" };
-
/* no need to dump the entire state, this is a sanity check */
#ifndef USE_QT
/* will fail on a 32-bit machine */
@@ -299,12 +296,16 @@ void libgps_dump_state(struct gps_data_t *collect)
(void)fprintf(debugfp, "TRACK: track: %lf\n", collect->fix.track);
if (collect->set & CLIMB_SET)
(void)fprintf(debugfp, "CLIMB: climb: %lf\n", collect->fix.climb);
- if (collect->set & STATUS_SET)
+ if (collect->set & STATUS_SET) {
+ const char *status_values[] = { "NO_FIX", "FIX", "DGPS_FIX" };
(void)fprintf(debugfp, "STATUS: status: %d (%s)\n",
collect->status, status_values[collect->status]);
- if (collect->set & MODE_SET)
+ }
+ if (collect->set & MODE_SET) {
+ const char *mode_values[] = { "", "NO_FIX", "MODE_2D", "MODE_3D" };
(void)fprintf(debugfp, "MODE: mode: %d (%s)\n",
collect->fix.mode, mode_values[collect->fix.mode]);
+ }
if (collect->set & DOP_SET)
(void)fprintf(debugfp,
"DOP: satellites %d, pdop=%lf, hdop=%lf, vdop=%lf\n",
diff --git a/net_dgpsip.c b/net_dgpsip.c
index acb463e3..f7209534 100644
--- a/net_dgpsip.c
+++ b/net_dgpsip.c
@@ -21,7 +21,6 @@
int dgpsip_open(struct gps_device_t *device, const char *dgpsserver)
/* open a connection to a DGPSIP server */
{
- char hn[256], buf[BUFSIZ];
char *colon, *dgpsport = "rtcm-sc104";
int opts;
@@ -36,6 +35,7 @@ int dgpsip_open(struct gps_device_t *device, const char *dgpsserver)
device->gpsdata.gps_fd =
netlib_connectsock(AF_UNSPEC, dgpsserver, dgpsport, "tcp");
if (device->gpsdata.gps_fd >= 0) {
+ char hn[256], buf[BUFSIZ];
gpsd_report(LOG_PROG, "connection to DGPS server %s established.\n",
dgpsserver);
(void)gethostname(hn, sizeof(hn));
diff --git a/timebase.c b/timebase.c
index 38b6e951..28ed42b9 100644
--- a/timebase.c
+++ b/timebase.c
@@ -135,11 +135,10 @@ void gpsd_set_century(struct gps_device_t *session)
* started up in.
*/
{
- unsigned char *cp;
char *end;
if (strstr((char *)session->packet.outbuffer, "Date:") != NULL) {
int year;
- cp = session->packet.outbuffer + 5;
+ unsigned char *cp = session->packet.outbuffer + 5;
while (isspace(*cp))
--cp;
year = (int)strtol((char *)cp, &end, 10);