Newsgroups: comp.lang.c Path: utzoo!henry From: henry@zoo.toronto.edu (Henry Spencer) Subject: Re: space allocation for sprintf() Message-ID: <1991Jun6.162723.27307@zoo.toronto.edu> Date: Thu, 6 Jun 1991 16:27:23 GMT References: <1991Jun5.174543.266@dg-rtp.dg.com> Organization: U of Toronto Zoology In article <1991Jun5.174543.266@dg-rtp.dg.com> vook@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@zoo.toronto.edu utzoo!henry