From 05501852ecb0bd3d048273c0ac063fe739983d8d Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 22 Apr 2004 20:17:54 +0000 Subject: [PATCH] Add testcases for g_message() involving non-printable and unsafe 2004-04-22 Matthias Clasen * tests/testglib.c (main): Add testcases for g_message() involving non-printable and unsafe characters. * glib/gmessages.c (escape_string): Don't assume that string->str remains unchanged over g_string_insert() calls. (#139030, Christophe Saout) --- ChangeLog | 7 +++++++ ChangeLog.pre-2-10 | 7 +++++++ ChangeLog.pre-2-12 | 7 +++++++ ChangeLog.pre-2-4 | 7 +++++++ ChangeLog.pre-2-6 | 7 +++++++ ChangeLog.pre-2-8 | 7 +++++++ glib/gmessages.c | 22 ++++++++++++++-------- tests/testglib.c | 2 ++ 8 files changed, 58 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index b6c1976a..fe7d1602 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2004-04-22 Matthias Clasen + * tests/testglib.c (main): Add testcases for g_message() involving + non-printable and unsafe characters. + + * glib/gmessages.c (escape_string): Don't assume that + string->str remains unchanged over g_string_insert() + calls. (#139030, Christophe Saout) + * glib/gstrfuncs.c (g_ascii_strtod): Fix problems when a locale-specific decimal separator directly follows a number. (#138424, Nickolay V. Shmyrev) diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index b6c1976a..fe7d1602 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,5 +1,12 @@ 2004-04-22 Matthias Clasen + * tests/testglib.c (main): Add testcases for g_message() involving + non-printable and unsafe characters. + + * glib/gmessages.c (escape_string): Don't assume that + string->str remains unchanged over g_string_insert() + calls. (#139030, Christophe Saout) + * glib/gstrfuncs.c (g_ascii_strtod): Fix problems when a locale-specific decimal separator directly follows a number. (#138424, Nickolay V. Shmyrev) diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index b6c1976a..fe7d1602 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,5 +1,12 @@ 2004-04-22 Matthias Clasen + * tests/testglib.c (main): Add testcases for g_message() involving + non-printable and unsafe characters. + + * glib/gmessages.c (escape_string): Don't assume that + string->str remains unchanged over g_string_insert() + calls. (#139030, Christophe Saout) + * glib/gstrfuncs.c (g_ascii_strtod): Fix problems when a locale-specific decimal separator directly follows a number. (#138424, Nickolay V. Shmyrev) diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index b6c1976a..fe7d1602 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,5 +1,12 @@ 2004-04-22 Matthias Clasen + * tests/testglib.c (main): Add testcases for g_message() involving + non-printable and unsafe characters. + + * glib/gmessages.c (escape_string): Don't assume that + string->str remains unchanged over g_string_insert() + calls. (#139030, Christophe Saout) + * glib/gstrfuncs.c (g_ascii_strtod): Fix problems when a locale-specific decimal separator directly follows a number. (#138424, Nickolay V. Shmyrev) diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index b6c1976a..fe7d1602 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,5 +1,12 @@ 2004-04-22 Matthias Clasen + * tests/testglib.c (main): Add testcases for g_message() involving + non-printable and unsafe characters. + + * glib/gmessages.c (escape_string): Don't assume that + string->str remains unchanged over g_string_insert() + calls. (#139030, Christophe Saout) + * glib/gstrfuncs.c (g_ascii_strtod): Fix problems when a locale-specific decimal separator directly follows a number. (#138424, Nickolay V. Shmyrev) diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index b6c1976a..fe7d1602 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,5 +1,12 @@ 2004-04-22 Matthias Clasen + * tests/testglib.c (main): Add testcases for g_message() involving + non-printable and unsafe characters. + + * glib/gmessages.c (escape_string): Don't assume that + string->str remains unchanged over g_string_insert() + calls. (#139030, Christophe Saout) + * glib/gstrfuncs.c (g_ascii_strtod): Fix problems when a locale-specific decimal separator directly follows a number. (#138424, Nickolay V. Shmyrev) diff --git a/glib/gmessages.c b/glib/gmessages.c index 4be1d548..fffd4027 100644 --- a/glib/gmessages.c +++ b/glib/gmessages.c @@ -791,16 +791,19 @@ escape_string (GString *string) if (wc == (gunichar)-1 || wc == (gunichar)-2) { gchar *tmp; - - g_string_erase (string, p - string->str, 1); + guint pos; + + pos = p - string->str; + /* Emit invalid UTF-8 as hex escapes */ tmp = g_strdup_printf ("\\x%02x", (guint)(guchar)*p); - g_string_insert (string, p - string->str, tmp); - g_free (tmp); + g_string_erase (string, pos, 1); + g_string_insert (string, pos, tmp); - p += 4; /* Skip over escape sequence */ + p = string->str + (pos + 4); /* Skip over escape sequence */ + g_free (tmp); continue; } if (wc == '\r') @@ -815,16 +818,19 @@ escape_string (GString *string) if (!safe) { gchar *tmp; + guint pos; + + pos = p - string->str; - g_string_erase (string, p - string->str, g_utf8_next_char (p) - p); /* Largest char we escape is 0x0a, so we don't have to worry * about 8-digit \Uxxxxyyyy */ tmp = g_strdup_printf ("\\u%04x", wc); - g_string_insert (string, p - string->str, tmp); + g_string_erase (string, pos, g_utf8_next_char (p) - p); + g_string_insert (string, pos, tmp); g_free (tmp); - p += 6; /* Skip over escape sequence */ + p = string->str + (pos + 6); /* Skip over escape sequence */ } else p = g_utf8_next_char (p); diff --git a/tests/testglib.c b/tests/testglib.c index d0bd7bb1..4c9cc412 100644 --- a/tests/testglib.c +++ b/tests/testglib.c @@ -1230,6 +1230,8 @@ main (int argc, g_message ("the next warning is a test:"); string = NULL; g_print (string); + g_message ("non-printable UTF-8: \"\xc3\xa4\xda\x85\""); + g_message ("unsafe chars: \"\x10\x11\x12\n\t\x7f\x81\x82\x83\""); g_print ("checking endian macros (host is "); #if G_BYTE_ORDER == G_BIG_ENDIAN -- 2.34.1