From: Matthias Clasen Date: Thu, 5 Jun 2003 23:04:21 +0000 (+0000) Subject: Use g_vasprintf() and g_string_append_len(), thus enabling embedded nuls X-Git-Tag: GLIB_2_3_0~172 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cc777da9c1476d436f6f96d877a99c0c614a528d;p=platform%2Fupstream%2Fglib.git Use g_vasprintf() and g_string_append_len(), thus enabling embedded nuls 2003-06-06 Matthias Clasen * 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(). --- diff --git a/ChangeLog b/ChangeLog index 38cc491..b6d1fe8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2003-06-06 Matthias Clasen + * 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) diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 38cc491..b6d1fe8 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,5 +1,12 @@ 2003-06-06 Matthias Clasen + * 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) diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 38cc491..b6d1fe8 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,5 +1,12 @@ 2003-06-06 Matthias Clasen + * 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) diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 38cc491..b6d1fe8 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,5 +1,12 @@ 2003-06-06 Matthias Clasen + * 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) diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 38cc491..b6d1fe8 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,5 +1,12 @@ 2003-06-06 Matthias Clasen + * 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) diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 38cc491..b6d1fe8 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,5 +1,12 @@ 2003-06-06 Matthias Clasen + * 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) diff --git a/glib/gstring.c b/glib/gstring.c index cdbda81..24d8b85 100644 --- a/glib/gstring.c +++ b/glib/gstring.c @@ -40,6 +40,7 @@ #include #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); } diff --git a/tests/string-test.c b/tests/string-test.c index abd85bc..b328e9c 100644 --- a/tests/string-test.c +++ b/tests/string-test.c @@ -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);