Hi, and thanx.

That code really is suffering without good reason.  I've replaced it with

$ svn diff trackfilter.c
Index: trackfilter.c
--- trackfilter.c (revision 4212)
+++ trackfilter.c (working copy)
@@ -943,9 +943,9 @@
         dest = route_head_alloc();
         dest->rte_num = src->rte_num;
         /* name in the form TRACKNAME #n */
-        snprintf(trk_seg_num_buf, sizeof(trk_seg_num_buf), "%d", ++trk_seg_num);
-        dest->rte_name = (char*) xmalloc(strlen(src->rte_name)+strlen(trk_seg_num_buf)+3);
-        sprintf(dest->rte_name, "%s #%s", src->rte_name, trk_seg_num_buf);
+        if (src->rte_name) {
+          xasprintf(&dest->rte_name, "%s #%s", src->rte_name, ++trk_seg_num);
+        }
         /* Insert after original track or after last newly
          * created track */

Please confirm this works out OK for you.


On Mon, Dec 3, 2012 at 4:59 AM, Bortel László <bortel@freemail.hu> wrote:

 Hi All,

Sorry, I used a wrong subject in my last mail.


  Hi All,

I think I have found a bug while processing the attached Pos.gpx file like this:

bortel@Server:~$ gpsbabel -D 1 -i gpx -f Pos.gpx -x track,seg2trk -o gpx -F Pos_trk.gpx
GPSBabel Version: 1.4.4
options: module/option=value: gpx/snlen="32" (=default)
options: module/option=value: track/seg2trk="1"
Segmentation fault

bortel@Server:~$ uname -a
Linux Server 2.6.32-5-686 #1 SMP Mon Jan 16 16:04:25 UTC 2012 i686 GNU/Linux

According to my analysis the Segmentation fault occurs in trackfilter.c in function trackfilter_seg2trk(void) because the track has no name, so src->rte_name is NULL.
To verify this finding I have implemented a check for "anonymous tracks" like this:

if (src->rte_name) {
        snprintf(trk_seg_num_buf, sizeof(trk_seg_num_buf), "%d", ++trk_seg_num);
        dest->rte_name = (char*) xmalloc(strlen(src->rte_name)+strlen(trk_seg_num_buf)+3);
        sprintf(dest->rte_name, "%s #%s", src->rte_name, trk_seg_num_buf);

The principle is that if the original track has no name then the descendant segment tracks should not have name either - so name construction should be skipped.
Please consider implementing this bug fix in next version.


Keep yourself connected to Go Parallel:
BUILD Helping you discover the best ways to construct your parallel projects.
Gpsbabel-code mailing list  http://www.gpsbabel.org