[GRASS5] [bug #1140] (grass) Non-portable snprintf() used in several programs
Glynn Clements
glynn.clements at virgin.net
Thu Jun 27 06:05:03 EDT 2002
Request Tracker wrote:
> It was also mentioned in the mailing list before that even on systems
> that do provide snprintf(), the return value when an error occurs is
> not standardised, so that is another reason for not relying on the
> system library version.
AFAIK, there are only two possible behaviours in this case:
1. Return a negative value
2. Return the number of characters which would have been written,
excluding the trailing NUL.
So, using:
n = snprintf(buff, size, ...);
if (n < 0 || n >= size)
G_fatal_error(...);
should handle either case.
That still doesn't solve the problem of needing snprintf() in the
first place. If we are going to rely upon a third-party library, we
should probably look for one which provides asprintf().
--
Glynn Clements <glynn.clements at virgin.net>
More information about the grass-dev
mailing list