minmea_scan("f"): allow spaces at the start of the field

This commit is contained in:
Kosma Moczek 2014-07-30 15:18:22 +02:00
parent b777fbe0b9
commit e81f908109
2 changed files with 17 additions and 0 deletions

View File

@ -166,6 +166,11 @@ bool minmea_scan(const char *sentence, const char *format, ...)
scale *= 10; scale *= 10;
} else if (*field == '.' && scale == 0) { } else if (*field == '.' && scale == 0) {
scale = 1; scale = 1;
} else if (*field == ' ') {
/* Allow spaces at the start of the field. Not NMEA
* conformant, but some modules do this. */
if (sign != 0 || value != -1 || scale != 0)
goto parse_error;
} else { } else {
goto parse_error; goto parse_error;
} }

12
tests.c
View File

@ -181,6 +181,18 @@ START_TEST(test_minmea_scan_f)
ck_assert(minmea_scan("foo,12.3", "_;f", &f) == true); ck_assert(minmea_scan("foo,12.3", "_;f", &f) == true);
ck_assert_int_eq(f.value, 123); ck_assert_int_eq(f.value, 123);
ck_assert_int_eq(f.scale, 10); ck_assert_int_eq(f.scale, 10);
/* accept spaces at the start of the field. some modules do this, unfortunately. */
ck_assert(minmea_scan(" -1.23,V", "f", &f) == true);
ck_assert_int_eq(f.value, -123);
ck_assert_int_eq(f.scale, 100);
ck_assert(minmea_scan(" -4.56,V", "f", &f) == true);
ck_assert_int_eq(f.value, -456);
ck_assert_int_eq(f.scale, 100);
ck_assert(minmea_scan("-3.33 ,V", "f", &f) == false);
ck_assert(minmea_scan(" -3.33 ,V", "f", &f) == false);
ck_assert(minmea_scan("-3. 33,V", "f", &f) == false);
ck_assert(minmea_scan("0 .0,V", "f", &f) == false);
} }
END_TEST END_TEST