From: robertlipe Date: Sat, 8 Dec 2012 08:27:32 +0000 (+0000) Subject: Make pocketfms reader more robust on a waypoint name with a space in it X-Git-Tag: archive/raspbian/1.10.0+ds-2+rpi1~1^2~12^2~11^2~743 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=ce21addd343c82d33fcd841da52b3998501b6583;p=gpsbabel.git Make pocketfms reader more robust on a waypoint name with a space in it and make the writer not include a space. --- diff --git a/gpsbabel/pocketfms_wp.c b/gpsbabel/pocketfms_wp.c index 8f53fed63..a43dce3fb 100644 --- a/gpsbabel/pocketfms_wp.c +++ b/gpsbabel/pocketfms_wp.c @@ -68,10 +68,20 @@ data_read(void) wpt = waypt_new(); s = buff; s = csv_lineparse(s, "\\w", "", linecount); + if (!s) { + fatal(MYNAME "Invalid name"); + } wpt->shortname = xstrdup(s); s = csv_lineparse(NULL, "\\w", "", linecount); + if (!s) { + fatal(MYNAME "Invalid latitude %s", wpt->shortname); + } wpt->latitude = wppos_to_dec(s); + s = csv_lineparse(NULL, "\\w", "", linecount); + if (!s) { + fatal(MYNAME "Invalid longitude %s", wpt->shortname); + } wpt->longitude = wppos_to_dec(s); waypt_add(wpt); } @@ -92,7 +102,24 @@ wr_init(const char *fname) static void enigma_waypt_disp(const waypoint *wpt) { - gbfprintf(file_out, "%s %f %f\n", wpt->shortname, wpt->latitude, wpt->longitude); + char *t; + if (wpt->shortname) { + // The output might have a space or control character. + int i, l = strlen(wpt->shortname); + t = xmalloc(l); + char *d = t; + for (i = 0; i < l; i++) { + char s = wpt->shortname[i]; + if(isgraph(s)) { + *d++ = s; + } + } + *d = 0; + } else { + t = xstrdup("NONAME"); + } + gbfprintf(file_out, "%s %f %f\n", t, wpt->latitude, wpt->longitude); + xfree(t); } static void