Re: [AD] SF.net SVN: alleg:[11645] allegro/branches/4.9/examples/ex_utf8.c |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
On 2009-02-22, Elias Pschernig <elias.pschernig@xxxxxxxxxx> wrote:
> On Sun, 2009-02-22 at 09:36 +1100, Peter Wang wrote:
> > On 2009-02-21, elias@xxxxxxxxxx <elias@xxxxxxxxxx> wrote:
> > > Revision: 11645
> > > http://alleg.svn.sourceforge.net/alleg/?rev=11645&view=rev
> > > Author: elias
> > > Date: 2009-02-21 15:43:42 +0000 (Sat, 21 Feb 2009)
> > >
> > > Log Message:
> > > -----------
> > > Added a testcase to ex_utf8 which crashes for me. Peter: Waiting for you to fix it before I start debugging it myself :)
> > >
> >
> > I can't reproduce it.
> >
>
> Oh well, seems to be one of "those" bugs. I was unable to figure out the
> cause of the crash, but I found if I set the size parameter of
> _al_bvcformata to at least 32, the crashes stop. Looks like the actual
> bug is in bstrlib. Or maybe I have a broken libc here? I committed the
> work-around of setting the size to 32 for now, and also fixed a
> constness warning.
Your constness comment made me look at the man page more closely:
The functions vprintf(), vfprintf(), vsprintf(), vsnprintf() are
equivalent to the functions printf(), fprintf(), sprintf(),
snprintf(), respectively, except that they are called with a va_list
instead of a variable number of arguments. These functions do not
call the va_end macro. Because they invoke the va_arg macro, the
value of ap is undefined after the call. See stdarg(3).
which makes the code in al_ustr_vappendf() invalid because it reuses
`ap' if it needs to repeat the vsnprintf call because the initial buffer
was too small. *That's* probably why I used to have a va_copy() call in
there, but it was taken out because va_copy() isn't implemented by MSVC.
Try reverting this following change and see if it fixes it for you.
We'll need to figure out how to do the same for MSVC, unfortunately.
Peter
diff --git a/src/utf8.c b/src/utf8.c
index dc7948b..46c065e 100644
--- a/src/utf8.c
+++ b/src/utf8.c
@@ -467,7 +467,6 @@ bool al_ustr_appendf(ALLEGRO_USTR us, const char *fmt, ...)
*/
bool al_ustr_vappendf(ALLEGRO_USTR us, const char *fmt, const va_list ap)
{
- va_list arglist;
int sz;
int rc;
@@ -479,10 +478,7 @@ bool al_ustr_vappendf(ALLEGRO_USTR us, const char *fmt, const va_list ap)
#endif
for (;;) {
- va_copy(arglist, ap);
- rc = _al_bvcformata(us.b, sz, fmt, arglist);
- va_end(arglist);
-
+ rc = _al_bvcformata(us.b, sz, fmt, ap);
if (rc >= 0) {
return true;
}