[GRASS-dev] Re: [bug #1140] (grass) Non-portable snprintf() used in several programs

Glynn Clements glynn at gclements.plus.com
Tue Jul 4 15:50:15 EDT 2006


Paul Kelly wrote:

> I contend that most of those recent introductions of snprintf() probably 
> don't need it. E.g. the first one (raster3d/r3.in.acii/main.c) can 
> calculate the length of the string to be malloc'ed using strlen() so can 
> guarantee to leave enough space. The second one (db/drivers/dbf/dbfexe.c) 
> can use a fixed field width specifier for the %d format string to fix the 
> length also - again predictable.

Field width specifiers only control the minimum width of a field (i.e. 
the amount of padding or the number of leading zeroes); a field can
still be larger than the specified width.

For %d, it's reasonable to assume a 32-bit integer, which means that
it can never be more than 11 characters wide (10 digits, with a
leading minus if negative).

-- 
Glynn Clements <glynn at gclements.plus.com>




More information about the grass-dev mailing list