[GRASS-dev] clean_temp rewritten

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


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




More information about the grass-dev mailing list