[GRASS-dev] clean_temp rewritten

Markus Neteler neteler at itc.it
Sat Jun 24 16:18:09 EDT 2006


On Sat, Jun 24, 2006 at 09:06:58PM +0100, Paul Kelly wrote:
> 
> Markus Neteler wrote:
> [...]
> >>>>1. snprintf() is C99; not all systems have it.
> >>>
> >>>So far it is implemented a few times in GRASS:
> >>>
> >>>find . -type f -name "*.c" -exec grep -l snprintf {} \;
> >>>./raster3d/r3.in.ascii/main.c
> >>>./db/drivers/dbf/dbfexe.c
> >>>./raster/r.support/front/front.c
> >>>./raster/r.support/front/check.c
> >>>./raster/r.support/front/run.c
> >>>./raster/r.support/modhead/check_un.c
> >>>./raster/r.support/modhead/modhead.c
> >>>./raster/r.support/modhead/ask_format.c
> >>>./lib/db/sqlp/lex.yy.c
> >>>./lib/db/dbmi_client/select.c
> >>>./lib/gis/user_config.c
> >>>./lib/vector/dglib/examples/components.c
> 
> These must have been added fairly recently- at least, since the last
> time I tried compiling GRASS on IRIX because snprintf() usage always
> caused the compile to fail there...
> 
> I thought we decided to use G_asprintf() for situations like this.
> Indeed, it is there in SUBMITTING, point 10:
> 
> 10. Use the GRASS library function G_asprintf() instead of the
>     standard C functions asprintf(), vsnprintf() and snprintf().  These
>     functions are not portable or have other issues.  Example:
> 
>     char *msg;
> 
>     G_asprintf(&msg, "%s", parameters);
>     do_something_with_msg();
>     G_free(msg);
> 
>     Note that you should free memory when G_asprintf() is used.
> 
> 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()).

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

Markus




More information about the grass-dev mailing list