[GRASS5] Re: [bug #2767] (grass) r.stats bug (due to recent
tlaronde at polynum.com
tlaronde at polynum.com
Thu Dec 9 13:24:03 EST 2004
On Thu, Dec 09, 2004 at 10:35:16AM +0100, Markus Neteler wrote:
>
> ... also crashing:
>
> (gdb) r -anC fields,elevation.10m
> Starting program: /hardmnt/thuille0/ssi/software/cvsgrass57/dist.i686-pc-linux-gnu/bin/r.stats -anC fields,elevation.10m
>
> Program received signal SIGSEGV, Segmentation fault.
> 0x00306657 in G_set_raster_cats_title (title=0xbfffb3c0 "", pcats=0x7a2d4fd0) at cats.c:1536
> 1536 pcats->title = G_store (title);
This is the call to G_store (see the previous answer to Paul) since with
the code:
char *buf;
if (s == NULL)
*buf = '\0';
one is still writing the char '\0' to an unknown address since buf has
a random value (probably 0 in this case, leading to the SEGFAULT; and
no SEGFAULT on a system where buf, not initialized, happens to point
to some valid address---thus trashing some place it doesn't own).
So correct sequence here too: initialize (reserve address) before
writing to it:
if (s == NULL)
buf = (char *) calloc(1,1); /* 1 byte allocated and destination zeroed */
( same as doing:
buf = (char *) malloc(1);
*buf = '\0';
)
But I still have the intuition that you should test in r.stats, and not
change G_store().
If the program is still segfaulting with such a change, there is another
bug somewhere else...
Cheers,
--
Thierry Laronde (Alceste) <tlaronde +AT+ polynum +dot+ com>
http://www.kergis.org/ | http://www.kergis.com/
Key fingerprint = 0FF7 E906 FBAF FE95 FD89 250D 52B1 AE95 6006 F40C
More information about the grass-dev
mailing list