kosma / minmea

a lightweight GPS NMEA 0183 parser library in pure C
Do What The F*ck You Want To Public License
735 stars 246 forks source link

minmea_scan(): read check bit problem #78

Open yuanjinghh opened 2 months ago

yuanjinghh commented 2 months ago

Hi, When I was parsing GSV data, I found that in some cases, the incoming packet parsing failed. Then, I did error tracing and found that the last field of the packet is hexadecimal data, and when it starts with a letter, such as B0*2, strtol() fails to parse, returns 0(base is 10), and endptr points to B, minmea_isfield () returns true, and the parsing error exits.

 case 'i':
        { // Integer value, default 0 (int).
            int value = 0;

            if (field)
            {
                char *endptr;
                value = strtol(field, &endptr, 10);
                if (minmea_isfield(*endptr))
                    goto parse_error;
            }

            *va_arg(ap, int *) = value;
        }
        break;

However, it seems to me that this is a bug in the program, and it exists in other parsing, but I don't have a good way to solve it.I just fixed the problem for a while to meet my needs.

            if (field)
            {
                char *endptr;
                value = strtol(field, &endptr, 10);
                if (minmea_isfield(*endptr))
                {
                    if (strtol(field, &endptr, 16) != 0)
                        result = true;
                    goto parse_error;
            }

I don't know if there is any problem with my understanding, and I hope there is a better way to solve this problem. Thanks.

kosma commented 2 months ago

Please post:

Then I can adapt the library to parse the sentence.

yuanjinghh commented 2 months ago

Oh, I'm so sorry. It's my problem.