Use g_vasprintf() and g_string_append_len(), thus enabling embedded nuls
authorMatthias Clasen <maclas@gmx.de>
Thu, 5 Jun 2003 23:04:21 +0000 (23:04 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Thu, 5 Jun 2003 23:04:21 +0000 (23:04 +0000)
2003-06-06  Matthias Clasen  <maclas@gmx.de>

* glib/gstring.c (g_string_append_printf_internal): Use
g_vasprintf() and g_string_append_len(), thus enabling embedded
nuls in the result of g_string_printf().  (#92492, Owen Taylor)

* tests/string-test.c: Add a test for embedded nuls in the
result of g_string_printf().

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
glib/gstring.c
tests/string-test.c

index 38cc4919b272c4eab31d838458f14c28b290b8f9..b6d1fe8496d0ea98758b6139fb9df36834e0f62c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2003-06-06  Matthias Clasen  <maclas@gmx.de>
 
+       * glib/gstring.c (g_string_append_printf_internal): Use
+       g_vasprintf() and g_string_append_len(), thus enabling embedded
+       nuls in the result of g_string_printf().  (#92492, Owen Taylor)
+
+       * tests/string-test.c: Add a test for embedded nuls in the
+       result of g_string_printf().
+
        * glib/gprintf.[ch]: Synchronize argument names with headers and docs.
        (g_vasprintf): An implementation of vasprintf(), code was lifted
        from g_strdup_vprintf().  (#112365)
index 38cc4919b272c4eab31d838458f14c28b290b8f9..b6d1fe8496d0ea98758b6139fb9df36834e0f62c 100644 (file)
@@ -1,5 +1,12 @@
 2003-06-06  Matthias Clasen  <maclas@gmx.de>
 
+       * glib/gstring.c (g_string_append_printf_internal): Use
+       g_vasprintf() and g_string_append_len(), thus enabling embedded
+       nuls in the result of g_string_printf().  (#92492, Owen Taylor)
+
+       * tests/string-test.c: Add a test for embedded nuls in the
+       result of g_string_printf().
+
        * glib/gprintf.[ch]: Synchronize argument names with headers and docs.
        (g_vasprintf): An implementation of vasprintf(), code was lifted
        from g_strdup_vprintf().  (#112365)
index 38cc4919b272c4eab31d838458f14c28b290b8f9..b6d1fe8496d0ea98758b6139fb9df36834e0f62c 100644 (file)
@@ -1,5 +1,12 @@
 2003-06-06  Matthias Clasen  <maclas@gmx.de>
 
+       * glib/gstring.c (g_string_append_printf_internal): Use
+       g_vasprintf() and g_string_append_len(), thus enabling embedded
+       nuls in the result of g_string_printf().  (#92492, Owen Taylor)
+
+       * tests/string-test.c: Add a test for embedded nuls in the
+       result of g_string_printf().
+
        * glib/gprintf.[ch]: Synchronize argument names with headers and docs.
        (g_vasprintf): An implementation of vasprintf(), code was lifted
        from g_strdup_vprintf().  (#112365)
index 38cc4919b272c4eab31d838458f14c28b290b8f9..b6d1fe8496d0ea98758b6139fb9df36834e0f62c 100644 (file)
@@ -1,5 +1,12 @@
 2003-06-06  Matthias Clasen  <maclas@gmx.de>
 
+       * glib/gstring.c (g_string_append_printf_internal): Use
+       g_vasprintf() and g_string_append_len(), thus enabling embedded
+       nuls in the result of g_string_printf().  (#92492, Owen Taylor)
+
+       * tests/string-test.c: Add a test for embedded nuls in the
+       result of g_string_printf().
+
        * glib/gprintf.[ch]: Synchronize argument names with headers and docs.
        (g_vasprintf): An implementation of vasprintf(), code was lifted
        from g_strdup_vprintf().  (#112365)
index 38cc4919b272c4eab31d838458f14c28b290b8f9..b6d1fe8496d0ea98758b6139fb9df36834e0f62c 100644 (file)
@@ -1,5 +1,12 @@
 2003-06-06  Matthias Clasen  <maclas@gmx.de>
 
+       * glib/gstring.c (g_string_append_printf_internal): Use
+       g_vasprintf() and g_string_append_len(), thus enabling embedded
+       nuls in the result of g_string_printf().  (#92492, Owen Taylor)
+
+       * tests/string-test.c: Add a test for embedded nuls in the
+       result of g_string_printf().
+
        * glib/gprintf.[ch]: Synchronize argument names with headers and docs.
        (g_vasprintf): An implementation of vasprintf(), code was lifted
        from g_strdup_vprintf().  (#112365)
index 38cc4919b272c4eab31d838458f14c28b290b8f9..b6d1fe8496d0ea98758b6139fb9df36834e0f62c 100644 (file)
@@ -1,5 +1,12 @@
 2003-06-06  Matthias Clasen  <maclas@gmx.de>
 
+       * glib/gstring.c (g_string_append_printf_internal): Use
+       g_vasprintf() and g_string_append_len(), thus enabling embedded
+       nuls in the result of g_string_printf().  (#92492, Owen Taylor)
+
+       * tests/string-test.c: Add a test for embedded nuls in the
+       result of g_string_printf().
+
        * glib/gprintf.[ch]: Synchronize argument names with headers and docs.
        (g_vasprintf): An implementation of vasprintf(), code was lifted
        from g_strdup_vprintf().  (#112365)
index cdbda81576d22a318743fa4bd7580098e340c27b..24d8b8592d4e698fed12980c226e441125577dc7 100644 (file)
@@ -40,6 +40,7 @@
 #include <ctype.h>
 
 #include "glib.h"
+#include "gprintf.h"
 
 
 struct _GStringChunk
@@ -780,9 +781,10 @@ g_string_append_printf_internal (GString     *string,
                                 va_list      args)
 {
   gchar *buffer;
-
-  buffer = g_strdup_vprintf (fmt, args);
-  g_string_append (string, buffer);
+  gint length;
+  
+  length = g_vasprintf (&buffer, fmt, args);
+  g_string_append_len (string, buffer, length);
   g_free (buffer);
 }
 
index abd85bc81aa461f3a4cae38474110b3a25a1953f..b328e9cc81b5ebc056ff59b605790d283c6988b9 100644 (file)
@@ -208,6 +208,10 @@ main (int   argc,
   g_assert ( memcmp(string1->str, "fiddle\0xyzzy", 13) == 0);
   g_string_insert(string1, 1, "QED");
   g_assert ( memcmp(string1->str, "fQEDiddle\0xyzzy", 16) == 0);
+  g_string_printf (string1, "fiddle%cxyzzy", '\0');
+  g_assert (string1->len == 12);
+  g_assert (memcmp (string1->str, "fiddle\0xyzzy", 13) == 0);
+
   g_string_free (string1, TRUE);
   g_string_free (string2, TRUE);