Re: Maybe we should use "snprintf" instead of "sprintf".

Ming-I Hsieh (mihs@wm28.csie.ncu.edu.tw)
Tue, 15 Jun 1999 22:11:40 +0800


michael@surfnetcity.com.au wrote:

> On Tue, Jun 15, 1999 at 12:31:16PM +0800, Ming-I Hsieh wrote:
> > sprintf(buf,"%.4fin",value);
> > ^^^^^^^^^ here, if we use "snprintf" instead of
> > "sprintf". I think it will
> > more stable! :)
>
> Down near the bottom of the snprintf(3) man page:
>
> CONFORMING TO
> These are GNU extensions.
>
> --
> -- Michael Samuel <michael@surfnetcity.com.au>

Because sprintf() and vsprintf() assume an infinitely long string,
callers must be careful not to overflow the actual space; this is
often
hard to assure. For safety, programmers should use the snprintf()
inter-
face instead. Unfortunately, this interface is not portable.

Ok! But there aren't others function can instend of sprintf? If not,
maybe we should think a way to pack sprintf. Otherwise, we will waste
some space to make a ``infinitely long string''.



This archive was generated by hypermail 1.03b2.