mirror of
https://github.com/adafruit/Adafruit_GPS.git
synced 2026-10-27 06:20:18 +00:00
Merge pull request #166 from ladyada-eagleclaw/fix-null-field-check
Check for NULL before reading an NMEA field
This commit is contained in:
2 files changed
+44
-1
No files matched your search
@@ -0,0 +1,43 @@
|
||||
// Test the private field helper without changing the library's public API.
|
||||
#include <Arduino.h>
|
||||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
#define private public
|
||||
#include <Adafruit_GPS.h>
|
||||
#undef private
|
||||
|
||||
Adafruit_GPS GPS;
|
||||
bool testsPassed = false;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
// Wait briefly for the Serial Monitor on native USB boards.
|
||||
while (!Serial && millis() < 5000) {
|
||||
delay(10);
|
||||
}
|
||||
delay(250);
|
||||
Serial.println("Adafruit GPS NULL field regression");
|
||||
|
||||
char field[] = "123,";
|
||||
if (GPS.isEmpty(field)) {
|
||||
Serial.println("FAIL: a populated field was reported empty");
|
||||
return;
|
||||
}
|
||||
Serial.println("PASS: populated field is not empty");
|
||||
|
||||
if (!GPS.isEmpty(NULL)) {
|
||||
Serial.println("FAIL: a NULL field was not reported empty");
|
||||
return;
|
||||
}
|
||||
Serial.println("PASS: NULL field is empty");
|
||||
testsPassed = true;
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (testsPassed) {
|
||||
Serial.println("PASS: NULL field regression");
|
||||
} else {
|
||||
Serial.println("FAIL: NULL field regression");
|
||||
}
|
||||
delay(2000);
|
||||
}
|
||||
+1
-1
@@ -848,7 +848,7 @@ bool Adafruit_GPS::parseAntenna(char *p) {
|
||||
*/
|
||||
/**************************************************************************/
|
||||
bool Adafruit_GPS::isEmpty(char *pStart) {
|
||||
if (',' != *pStart && '*' != *pStart && pStart != NULL)
|
||||
if (pStart != NULL && ',' != *pStart && '*' != *pStart)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
|
||||
Reference in new issue
Block a user