From: Ole André Vadla Ravnås Date: Sun, 29 Mar 2009 00:44:44 +0000 (+0100) Subject: Fix broken Windows implementation of _dbus_printf_string_upper_bound(). X-Git-Tag: dbus-1.3.1~221 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=29e8f9917ab53db91aa746e25b71e8bcfe698171;p=platform%2Fupstream%2Fdbus.git Fix broken Windows implementation of _dbus_printf_string_upper_bound(). Pass the correct buffer size when trying again, and keep trying with larger buffer sizes, doubling the size each time. (cherry picked from commit 95832a94607eea609de994467b7d64e36af72e6b) --- diff --git a/dbus/dbus-sysdeps-win.c b/dbus/dbus-sysdeps-win.c index 126ffee..5dd1ca9 100644 --- a/dbus/dbus-sysdeps-win.c +++ b/dbus/dbus-sysdeps-win.c @@ -658,23 +658,24 @@ int _dbus_printf_string_upper_bound (const char *format, va_list args) { /* MSVCRT's vsnprintf semantics are a bit different */ - /* The C library source in the Platform SDK indicates that this - * would work, but alas, it doesn't. At least not on Windows - * 2000. Presumably those sources correspond to the C library on - * some newer or even future Windows version. - * - len = _vsnprintf (NULL, _DBUS_INT_MAX, format, args); - */ - char p[1024]; + char buf[1024]; + int bufsize; int len; - len = _vsnprintf (p, sizeof(p)-1, format, args); - if (len == -1) // try again + + bufsize = sizeof (buf); + len = _vsnprintf (buf, bufsize - 1, format, args); + + while (len == -1) /* try again */ { char *p; - p = malloc (strlen(format)*3); - len = _vsnprintf (p, sizeof(p)-1, format, args); - free(p); + + bufsize *= 2; + + p = malloc (bufsize); + len = _vsnprintf (p, bufsize - 1, format, args); + free (p); } + return len; }