[GRASS5] Re: NVIZ + CELL map + gcc >=3.2.2 = SegFault

Hamish hamish_nospam at yahoo.com
Wed Sep 17 06:11:09 EDT 2003


Bug #2:  (got it.)

> > > It apparently breaks while somewhere in this statement in
> > >  src/libes/gis/nme_in_mps.c:
> > > 
> > > if(strchr(name, '@'))
> > >         sprintf (fullname, "%s", name);
> > >     else
> > >         sprintf (fullname, "%s@%s", name, mapset);
> >
> > If strchr() segfaults, it means that name is bogus (either the
> > pointer itself is invalid or the data to which it points doesn't
> > have a terminating NUL).
> 
> Upon closer look, it appears to get the segfault when I access
> 'mapset', which explains why it would crash on the second+ pass
> through that function.
> 
> I'll have to work backwards from there.


In src/libes/ogsf/GS2.c's  GS_load_att_map(), the 'mapset' variable is
used uninitialized if "reuse" is true.

Moving the 'mapset=xxxx;' bit out of the condition to about line 1257
just before 'if (reuse)' stops the segfault; see the attached patch.

Could someone please test & commit to CVS if it's good, as I'll be out
of town until next week & won't be able to.

Looks ok, but I'm not really sure how much "reuse" reuses.. no chance of
using the wrong mapset from a previous call is there? That would be a
very ugly bug to catch.



forwards in all directions,
Hamish
-------------- next part --------------
--- src/libes/ogsf/GS2.c.ORIG	2002-08-13 09:45:19.000000000 +1200
+++ src/libes/ogsf/GS2.c	2003-09-17 21:55:09.000000000 +1200
@@ -1254,6 +1254,9 @@
 	begin = 0;
     }
 
+    /* Get MAPSET to ensure names are fully qualified */
+    mapset = G_find_cell2 (filename, "");
+
     if (reuse)
     {
 	gs->att[att].hdata = hdata;
@@ -1290,8 +1293,6 @@
 
 	tbuff = gs_get_att_typbuff(gs, att, 1);
 
-        /* Get MAPSET to ensure names are fully qualified */
-        mapset = G_find_cell2 (filename, "");
         filename = G_fully_qualified_name(filename, mapset);
 
 	/* TODO: Provide mechanism for loading certain attributes at


More information about the grass-dev mailing list