Hi, after upgrading from glib-2.2 to glib-2.6 the win32 version of Sylpheed-Claws crashes when invoking g_vsnprintf() with a "%s" format string and a NULL as argument. The former trio implementation handled this by replacing NULL with "(nil)", on linux (glib-2.6.3/debian unstable) the NULL is replaced by a valid string ("null") as well. Admittedly, printing NULL is bad style, but happens quite often in debug output. I patched the gnulib code to handle the NULL case, see the attached glib-vasnprintf.patch (against glib-2.6.4 tarball), a small test app is attached as well. Is it possible to include this patch (or is there interest at all in making gnulib handle the NULL case without crash)? Best regards, -- Thorsten Maerz <torte netztorte de> Sylpheed-claws/Win32: http://claws-w32.sf.net
# glib-vasnprintf.patch: # prevent crash with g_vsnprintf("%s",NULL) diff -ur glib-2.6.3-org/glib/gnulib/vasnprintf.c glib/glib/gnulib/vasnprintf.c --- glib-2.6.3-org/glib/gnulib/vasnprintf.c Fri May 14 04:58:19 2004 +++ glib/glib/gnulib/vasnprintf.c Sat Apr 30 10:43:47 2005 @@ -539,11 +539,15 @@ # ifdef HAVE_WCHAR_T if (type == TYPE_WIDE_STRING) tmp_length = - wcslen (a.arg[dp->arg_index].a.a_wide_string) - * MB_CUR_MAX; + (a.arg[dp->arg_index].a.a_wide_string) + ? wcslen (a.arg[dp->arg_index].a.a_wide_string) + * MB_CUR_MAX + : wcslen (L"(null)") * MB_CUR_MAX; else # endif - tmp_length = strlen (a.arg[dp->arg_index].a.a_string); + tmp_length = (a.arg[dp->arg_index].a.a_string) + ? strlen (a.arg[dp->arg_index].a.a_string) + : strlen ("(null)"); break; case 'p': @@ -906,14 +910,14 @@ case TYPE_STRING: { const char *arg = a.arg[dp->arg_index].a.a_string; - SNPRINTF_BUF (arg); + SNPRINTF_BUF ((arg) ? arg : "(null)"); } break; #ifdef HAVE_WCHAR_T case TYPE_WIDE_STRING: { const wchar_t *arg = a.arg[dp->arg_index].a.a_wide_string; - SNPRINTF_BUF (arg); + SNPRINTF_BUF ((arg) ? arg : L"(null)"); } break; #endif
#include <stdio.h> #include <glib.h> void xprintf(const gchar *format, ...) { va_list args; gchar buf[256]; va_start(args, format); g_vsnprintf(buf, sizeof(buf), format, args); va_end(args); printf("%s\n", buf); } int main( int argc, char *argv[] ) { xprintf("Hello %s\n", NULL, NULL); return 0; }
Attachment:
pgpX8BMNYLd3u.pgp
Description: PGP signature