space allocation for sprintf()

Henry Spencer henry at zoo.toronto.edu
Fri Jun 7 02:27:23 AEST 1991


In article <1991Jun5.174543.266 at dg-rtp.dg.com> vook at narnia.rtp.dg.com (Eric R Vook) writes:
>"(It is the programmer's responsibility to ensure that the destination
>  string area is large enough to contain the output generated by the
>  formatting operation.)"
>
>    How do you know how much space to allocate?
>    How do you know when you didn't allocate enough?

The fast answers are "you have to know how sprintf is being used and figure
out the longest string your parameters can result in" and "basically, you
don't".  A length-limited sprintf was repeatedly proposed to X3J11, and
might have made it into ANSI C if there had been some experience with it.
-- 
"We're thinking about upgrading from    | Henry Spencer @ U of Toronto Zoology
SunOS 4.1.1 to SunOS 3.5."              |  henry at zoo.toronto.edu  utzoo!henry



More information about the Comp.lang.c mailing list