Use strsep for NMEA message tokenization
authorPetr Štetiar <ynezz@true.cz>
Wed, 27 Jul 2016 12:45:51 +0000 (14:45 +0200)
committerJohn Crispin <john@phrozen.org>
Sun, 24 Jul 2016 04:12:43 +0000 (06:12 +0200)
strtok doesn't parse correctly following message:

  $GPGSA,A,1,,,,,,,,,,,,,,,*1E

Resulting in "datagram has wrong parameter count".

Signed-off-by: Petr Štetiar <ynezz@true.cz>
nmea.c

diff --git a/nmea.c b/nmea.c
index 05c904d6426668a59cc3bb4a763779e7d89c4d32..3646a3628aa914065b7e72890bc3ed7173d6fe52 100644 (file)
--- a/nmea.c
+++ b/nmea.c
@@ -221,13 +221,13 @@ static int
 nmea_tokenize(char *msg)
 {
        int cnt = 0;
-       char *tok = strtok(msg, ",");
+       char *tok = strsep(&msg, ",");
 
        while (tok && cnt < MAX_NMEA_PARAM) {
                nmea_params[cnt].str = tok;
                nmea_params[cnt].num = atoi(tok);
                cnt++;
-               tok = strtok(NULL, ",");
+               tok = strsep(&msg, ",");
        }
 
        return cnt;