diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2005-01-05 19:11:03 +0000 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2005-01-05 19:11:03 +0000 |
commit | d5b004b60776807e903dfa80e9e502709397e6e5 (patch) | |
tree | 87e1b8c11d6334b325c101fce3b40335421a7140 | |
parent | 546e181a3845ebbc70f00f41572f0357433c72ad (diff) | |
download | gpsd-d5b004b60776807e903dfa80e9e502709397e6e5.tar.gz |
Fix a nasty bug in field(), it didn't do the right thing for field
indices off the end of the sentence. This caused bugs in GSV parsing.
-rw-r--r-- | nmea_parse.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/nmea_parse.c b/nmea_parse.c index d160920e..a0f5b1a6 100644 --- a/nmea_parse.c +++ b/nmea_parse.c @@ -13,16 +13,19 @@ * **************************************************************************/ -static char *field(char *sentence, short n) +static char *field(char *sentence, short fn) /* return the nth comma-delimited field from the sentence */ { static char result[100]; char c, *p = sentence; - unsigned int i; + unsigned int i; int n = fn; - while (n-- > 0) + while (n-- > 0) { while ((c = *p++) != ',' && c != '\0') continue; + if (c == '\0' && n >= 0) + return ""; + } strncpy(result, p, sizeof(result)-1); p = result; i = 0; |