diff options
author | Thomas Gubler <thomasgubler@gmail.com> | 2014-12-23 09:20:00 +0100 |
---|---|---|
committer | Thomas Gubler <thomasgubler@gmail.com> | 2014-12-23 09:20:00 +0100 |
commit | ba4b8c8e003d5dba3b547f4b75407b584df5d965 (patch) | |
tree | d6abb29e334e8202fa7e57d74b15ad7d1ba814cd /src | |
parent | 6a8ebc8afded9fbf8f0221885f252ce427a3ce85 (diff) | |
parent | 82383533c169e44ac769ce77f9e8ddfbd3082ed9 (diff) | |
download | px4-firmware-ba4b8c8e003d5dba3b547f4b75407b584df5d965.tar.gz px4-firmware-ba4b8c8e003d5dba3b547f4b75407b584df5d965.tar.bz2 px4-firmware-ba4b8c8e003d5dba3b547f4b75407b584df5d965.zip |
Merge pull request #1523 from bansiesta/geofence_parse_fix
Geofence parse fix
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/navigator/geofence.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/modules/navigator/geofence.cpp b/src/modules/navigator/geofence.cpp index 0f431ded2..4482fb36b 100644 --- a/src/modules/navigator/geofence.cpp +++ b/src/modules/navigator/geofence.cpp @@ -279,8 +279,14 @@ Geofence::loadFromFile(const char *filename) while((textStart < sizeof(line)/sizeof(char)) && isspace(line[textStart])) textStart++; /* if the line starts with #, skip */ - if (line[textStart] == commentChar) + if (line[textStart] == commentChar) { continue; + } + + /* if there is only a linefeed, skip it */ + if (line[0] == '\n') { + continue; + } if (gotVertical) { /* Parse the line as a geofence point */ @@ -291,8 +297,10 @@ Geofence::loadFromFile(const char *filename) /* Handle degree minute second format */ float lat_d, lat_m, lat_s, lon_d, lon_m, lon_s; - if (sscanf(line, "DMS %f %f %f %f %f %f", &lat_d, &lat_m, &lat_s, &lon_d, &lon_m, &lon_s) != 6) + if (sscanf(line, "DMS %f %f %f %f %f %f", &lat_d, &lat_m, &lat_s, &lon_d, &lon_m, &lon_s) != 6) { + warnx("Scanf to parse DMS geofence vertex failed."); return ERROR; + } // warnx("Geofence DMS: %.5f %.5f %.5f ; %.5f %.5f %.5f", (double)lat_d, (double)lat_m, (double)lat_s, (double)lon_d, (double)lon_m, (double)lon_s); @@ -301,9 +309,10 @@ Geofence::loadFromFile(const char *filename) } else { /* Handle decimal degree format */ - - if (sscanf(line, "%f %f", &(vertex.lat), &(vertex.lon)) != 2) + if (sscanf(line, "%f %f", &(vertex.lat), &(vertex.lon)) != 2) { + warnx("Scanf to parse geofence vertex failed."); return ERROR; + } } if (dm_write(DM_KEY_FENCE_POINTS, pointCounter, DM_PERSIST_POWER_ON_RESET, &vertex, sizeof(vertex)) != sizeof(vertex)) |