summaryrefslogtreecommitdiff
path: root/driver_nmea.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2011-03-29 06:41:09 -0400
committerEric S. Raymond <esr@thyrsus.com>2011-03-29 06:41:09 -0400
commit3ef1d9ecbef54ba5e4e6a8167a8dd5c5723aa94f (patch)
treeb7dcab4eb669ca6fe3fc18bd672bc53e5a3d2c57 /driver_nmea.c
parentc48d0caf13ce030166fedad354e4732584584f50 (diff)
downloadgpsd-3ef1d9ecbef54ba5e4e6a8167a8dd5c5723aa94f.tar.gz
Magic-number and strncpy elimination. All regression tests pass
Diffstat (limited to 'driver_nmea.c')
-rw-r--r--driver_nmea.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/driver_nmea.c b/driver_nmea.c
index 90746ce6..1ed293fc 100644
--- a/driver_nmea.c
+++ b/driver_nmea.c
@@ -26,7 +26,7 @@ static void do_lat_lon(char *field[], struct gps_fix_t *out)
char str[20], *p;
if (*(p = field[0]) != '\0') {
- strncpy(str, p, 20);
+ (void)strlcpy(str, p, sizeof(str));
(void)sscanf(p, "%lf", &lat);
m = 100.0 * modf(lat / 100.0, &d);
lat = d + m / 60.0;
@@ -36,7 +36,7 @@ static void do_lat_lon(char *field[], struct gps_fix_t *out)
out->latitude = lat;
}
if (*(p = field[2]) != '\0') {
- strncpy(str, p, 20);
+ (void)strlcpy(str, p, sizeof(str));
(void)sscanf(p, "%lf", &lon);
m = 100.0 * modf(lon / 100.0, &d);
lon = d + m / 60.0;
@@ -342,7 +342,7 @@ static gps_mask_t processGPGGA(int c UNUSED, char *field[],
session->gpsdata.status = STATUS_NO_FIX;
session->newdata.mode = MODE_NO_FIX;
} else
- (void)strncpy(session->driver.nmea.last_gga_timestamp,
+ (void)strlcpy(session->driver.nmea.last_gga_timestamp,
field[1],
sizeof(session->driver.nmea.last_gga_timestamp));
/* if we have a fix and the mode latch is off, go... */
@@ -1055,7 +1055,7 @@ gps_mask_t nmea_parse(char *sentence, struct gps_device_t * session)
/*@ -usedef @*//* splint 3.1.1 seems to have a bug here */
/* make an editable copy of the sentence */
- strncpy((char *)session->driver.nmea.fieldcopy, sentence, NMEA_MAX);
+ (void)strlcpy((char *)session->driver.nmea.fieldcopy, sentence, NMEA_MAX);
/* discard the checksum part */
for (p = (char *)session->driver.nmea.fieldcopy;
(*p != '*') && (*p >= ' ');)
@@ -1104,7 +1104,9 @@ gps_mask_t nmea_parse(char *sentence, struct gps_device_t * session)
(nmea_phrase[i].decoder) (count,
session->driver.nmea.field,
session);
- strncpy(session->gpsdata.tag, nmea_phrase[i].name, MAXTAGLEN);
+ (void)strlcpy(session->gpsdata.tag,
+ nmea_phrase[i].name,
+ MAXTAGLEN);
/*
* Must force this to be nz, as we're going to rely on a zero
* value to mean "no previous tag" later.