[GRASS-dev] clean_temp rewritten

Paul Kelly paul-grass at stjohnspoint.co.uk
Sat Jun 24 16:45:53 EDT 2006


Hello Markus
Markus Neteler wrote:
> On Sat, Jun 24, 2006 at 09:06:58PM +0100, Paul Kelly wrote:
>>Unless there are any problems with G_asprintf() or reasons why it should
>>not be used I propose we change the above snprintf() occurences to use
>>G_asprintf().
> 
> 
> Paul,
> 
> I think you are right with "fairly" new (some months).
> 
> I forgot to add Glynn's comment (to me):
> 
> On Tue, May 16, 2006 at 04:20:43AM +0100, Glynn Clements wrote:
> 
>>Changing the code to use G_asprintf() instead is one alternative
>>(although G_asprintf() uses a temporary file on systems which lack
>>asprintf()).

EXCEPT changes made on 30th Jan appear to change this functionality as 
far as I can see mean that G_asprintf() is *always* implemented using 
Eric Miller's temporary file method:
http://freegis.org/cgi-bin/viewcvs.cgi/grass6/include/gisdefs.h.diff?r1=1.46&r2=1.47

This would need to be sorted out I'd say.

> I take that for agreement with your observation.
> Is it a simple change or needs checks for the (number of) parameters?

Fairly simple. Just takes some care to make sure the string is G_free'd 
in the right place etc. As an example here are the changes that need to 
be made in raster3d./r3.in.ascii/main.c:

--- main.c~     2006-02-09 03:09:04.000000000 +0000
+++ main.c      2006-06-24 21:02:32.000000000 +0100
@@ -120,11 +120,13 @@
  readHeaderString  (FILE *fp, char *valueString, double *value)

  {
-  static char format[100];
+  char *format;

-  snprintf (format, 100, "%s %%lf", valueString); /*to avoid 
bufferoverflows we use snprintf*/
+  G_asprintf (&format, "%s %%lf", valueString); /*to avoid 
bufferoverflows we use G_asprintf*/
    if (fscanf (fp, format, value) != 1)
      fatalError ("readHeaderString: header value invalid");
+
+  G_free(format);

    while (fgetc (fp) != '\n');
  }


I could look at changing the others if we are agreed about it.

Paul




More information about the grass-dev mailing list