On Sun, 27 Jan 2002, Andreas Beck wrote:

> It seems to do the right thing. However I'd vote for testing it at
> configure time and complain if it does something else.

Erm... I'm surprised that it actually does this.  I always assumed
if you overran the given length no '\0' was printed and I provided
it myself e.g.

char foo[8];

snprintf(foo, 8, "%s", blah);
foo[7] = '\0';

or

char foo[8];

foo[7] = '\0';
snprintf(foo, 7, "%s", blah);

I think it is safest to do it this way even if the documented behavior
is indeed to null terminate.  The former is better of course since the
results are always essentially the same, but the latter works too
and can be more terse depending on the code flow, and the difference 
doesn't matter when you're just putting a limit for security purposes.

--
Brian

Reply via email to