[GRASS-dev] clean_temp rewritten
Glynn Clements
glynn at gclements.plus.com
Mon Jun 26 07:47:50 EDT 2006
Glynn Clements wrote:
> Personally, I suggest /not/ using G_asprintf() unless it's absolutely
> necessary (i.e. where you can't impose any sensible limit on the
> maximum length of the resulting string).
>
> snprintf() is simpler to use and more efficient (even on systems which
> use vasprintf(); for systems using the tempfile hack, the difference
> is even more significant).
Also, if you don't check the return value from snprintf(), the code
may well fail for other reasons.
> For systems lacking their own snprintf(), we can either use a
> third-party version, or just discard the length argument and use
> vsprintf().
Another alternative would be to sprintf() into an oversized buffer
then check the length of the result before copying to the original
buffer.
That would protect against most cases where the strings being passed
in have their own limits (e.g. a string read from a file with fgets()
can't be any longer than the buffer it was read into, options passed
via the command line can't exceed the system's limit on the length of
a command line, etc).
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-dev
mailing list