Re: [AD] to prefix or not to prefix (part 2)

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


> Yes, this is very true. I have written a printf()-style function for C++
> which constructs a `string' object, and is memory safe (and doesn't
> waste a single byte). I wrote everything from scratch, including the
> floating point renderer, so there is no chance of buffer overruns.

Allegro's uszprintf() doesn't truncate anything (up to INT_MAX bytes) and is
memory safe, except maybe for the floating point renderer that piggybacks to
the libc but it shouldn't be too hard to fix it (then of course memory
allocation wouldn't be optimal at all).

The problem comes from the textprintf() function itself: it needs to render
the string before drawing it onto the screen so needs to use an internal
buffer. Therefore you can bypass any buffer limitation by using only
uszprintf() and textout().

> I could port it back to C (perhaps using Allegro's Unicode routines),
> but it would be quite an undertaking, and error checking would be a
> nightmare without exceptions. It is also a fair chunk of code.

If you have some time to kill, you could take a look at the current
implementation of uszprintf() and fix whatever problem you find.

--
Eric Botcazou
ebotcazou@xxxxxxxxxx



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/