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

Caolan McNamara (Caolan.McNamara@ul.ie)
Tue, 15 Jun 1999 15:24:03 +0100 (IST)


On 15-Jun-99 Ming-I Hsieh wrote:
>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>
>
>>From FreeBSD: man 3 snprintf
> 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''.

snprintf is available as a separate unit, you could do a configure test
for its existance and on failure use your own copy of it. A copy of
snprintf is available at
http://www.csn.ul.ie/~caolan/publink/snprintf-1.1.tar.gz
i don't know what the original site was though.

C.

Real Life: Caolan McNamara * Doing: MSc in HCI
Work: Caolan.McNamara@ul.ie * Phone: +353-61-202699
URL: http://www.csn.ul.ie/~caolan * Sig: an oblique strategy
Simply a matter of work



This archive was generated by hypermail 1.03b2.