How to predict size of outcome of vsprintf?
Doug Gwyn
gwyn at smoke.BRL.MIL
Sun Mar 19 15:52:35 AEST 1989
In article <993 at etnibsd.UUCP> sean at etnibsd.UUCP (Sean McElroy) writes:
>O.K. Unix/C gurus, since vsprintf requires the user to ensure that there
>is enough space in the output string, how does one predict the size of
>the output string? Is there a routine which returns the predicted
>length of the output string (effectively preforming the printf conversions)
>without actually producing the output string?
No. Sometimes you can accurately predict an upper bound on the output
string length; for example if the format is "%d" and the numerical
argument is known to lie between 0 and 5000, the maximum number of
characters for the *sprintf() output will be 5 (including the null
byte at the end).
>Any suggestions welcome.
Don't use *sprintf() when you can't be sure that the output length
will be small enough. Seriously.
More information about the Comp.unix.wizards
mailing list