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

Shaw Terwilliger (sterwill@postman.abisource.com)
Tue, 15 Jun 1999 22:41:07 -0500


Justin Bradford wrote:
>
> > An "infinately long string" is easy to figure out, you figure out the number
> > of characters the format string, and each of it's elements take up.
> >
> > If we wanted, we could even do a vsprintf() hack that would malloc() the
> > string automatically. (Yes, I know there's a GNU extension that will do this
> > already)
>
> It's not quite as easy as it sounds. You basically have to rewrite *printf
> functionality, which is quite a pain. I had to do something similar for a
> webserver I wrote a while back. I wanted the module api to be able to do
> *printf writes back to the client, but I had buffer overruns to worry
> about.
>
> If there's a nice GNU alternative, take that code. If not, I can
> contribute the simple function I have (only %u, %i, %x, and %s, I believe
> -- no formatting either).

I was digging through glibc2 documentation a long time ago and it
does provide dynamic printf() functions which allocate their own
memory. They work on dynamic strings, which are recommended usage
for all GNU project programs (to prevent things like buffer overflows).
It might have been mentioned earlier in this thread. From asprintf(3):

...asprintf and vasprintf
write to a dynamically allocated buffer, whose address is
returned in *strp; dprintf and vdprintf write to the given
file descriptor.

Since we're working under the GPL, we can just use the glibc2
implementations. We've done this for strstr, which is nice and
fast.

> P.S. The DSL line should be installed in 4-6 days now, so I'll be able to
> pick up Word import/export development again. I hope to have have support
> for both in by 1.0.

Great. I'm just now having time to start working on it again.

-- 
Shaw Terwilliger


This archive was generated by hypermail 1.03b2.