Bug 167569 - g_string_append_printf crashes on win32 when used with a NULL
authorTor Lillqvist <tml@novell.com>
Fri, 27 Feb 2009 07:46:32 +0000 (07:46 +0000)
committerTor Lillqvist <tml@src.gnome.org>
Fri, 27 Feb 2009 07:46:32 +0000 (07:46 +0000)
2009-02-27  Tor Lillqvist  <tml@novell.com>

Bug 167569 - g_string_append_printf crashes on win32 when used
with a NULL argument

* glib/gnulib/vasnprintf.c (vasnprintf): Add workaround for buggy
programs. Patch by Owen.

svn path=/trunk/; revision=7917

ChangeLog
glib/gnulib/vasnprintf.c

index 9e164c4d69dca592c98c2db1b10f3609e9353f66..db14272a54fce0b00d0ca9361a20563dbe6fcfdc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2009-02-27  Tor Lillqvist  <tml@novell.com>
+
+       Bug 167569 - g_string_append_printf crashes on win32 when used
+       with a NULL argument
+
+       * glib/gnulib/vasnprintf.c (vasnprintf): Add workaround for buggy
+       programs. Patch by Owen.
+
 2009-02-23  Paolo Borelli  <pborelli@katamail.com>
 
        * glib/gutf8.c (_g_utf8_make_valid):
index a8e9cc02f1fe8ade3b27231ee8be9b03b4f6b1f3..c981059f954bf5dec8bd1ca2848120ac96d6f261 100644 (file)
@@ -574,11 +574,15 @@ vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args)
 # ifdef HAVE_WCHAR_T
                      if (type == TYPE_WIDE_STRING)
                        tmp_length =
-                         local_wcslen (a.arg[dp->arg_index].a.a_wide_string)
+                         (a.arg[dp->arg_index].a.a_wide_string == NULL
+                         ? 6 /* wcslen(L"(null)") */
+                          : local_wcslen (a.arg[dp->arg_index].a.a_wide_string)) 
                          * 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 == NULL
+                         ? 6 /* strlen("(null)") */
+                         : strlen (a.arg[dp->arg_index].a.a_string);
                      break;
 
                    case 'p':
@@ -948,14 +952,18 @@ vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args)
 #endif
                      case TYPE_STRING:
                        {
-                         const char *arg = a.arg[dp->arg_index].a.a_string;
+                         const char *arg = a.arg[dp->arg_index].a.a_string == NULL
+                           ? "(null)"
+                           : a.arg[dp->arg_index].a.a_string;
                          SNPRINTF_BUF (arg);
                        }
                        break;
 #ifdef HAVE_WCHAR_T
                      case TYPE_WIDE_STRING:
                        {
-                         const wchar_t *arg = a.arg[dp->arg_index].a.a_wide_string;
+                         const wchar_t *arg = a.arg[dp->arg_index].a.a_wide_string == NULL
+                           ? L"(null)"
+                           : a.arg[dp->arg_index].a.a_wide_string;
                          SNPRINTF_BUF (arg);
                        }
                        break;