[GRASS5] Re: [bug #2767] (grass) r.stats bug (due to recent G_store() fix?)

Paul Kelly paul-grass at stjohnspoint.co.uk
Wed Dec 8 15:51:04 EST 2004


Hello Thierry

On Tue, 7 Dec 2004 tlaronde at polynum.com wrote:

> Hello,
>
> I haven't look at the code you are trying to fix (I have some other
> stuff ;-), but here are some tips :
>
[...]
Snip explanation of why my suggested fix was completely wrong
[...]
>
> So a correct sequence is :
>
> title = (char *) malloc(expected_size_of_string_plus_trailing_null);
> *title = '\0'; /* default to empty if intitle not set */
>

The first line here is more or less what G_store() does. But the recent 
change added
if ( s == NULL ) return NULL ;
to G_store.

Perhaps (going by what you suggest above) it should look more like:
char *G_store (char *s)
{
   char *buf;

   if ( s == NULL )
     *buf = '\0';
   else
   {
     buf = G_malloc (strlen(s) + 1);
     strcpy (buf, s);
   }
   return buf;
}

so you are returning a pointer to an empty string rather than returning a 
NULL pointer. But I am still not very hopeful.

The funny thing is I am unable to reproduce this bug so cannot test. 
Running 'r.stats -anC fields' in Spearfish with yesterday's 5.7 CVS on IRIX 
produces normal-looking output.

Paul




More information about the grass-dev mailing list