diff options
author | Jan-Michael Brummer <jan.brummer@tabos.org> | 2019-05-03 12:55:37 +0000 |
---|---|---|
committer | Michael Catanzaro <mcatanzaro@posteo.net> | 2019-05-05 01:09:21 +0000 |
commit | 5e8f11f20c73378d12be52ccc73072d0b564ec8e (patch) | |
tree | 7323b56ceeb9f0f294ec6a2e16a353b7d0f3c5ff | |
parent | 854dbd602ddcd8409a9ecfda7cdf1396614cf3f4 (diff) | |
download | epiphany-5e8f11f20c73378d12be52ccc73072d0b564ec8e.tar.gz |
Fix segfaulting eel_strdup_strftime ()
Fixes: https://gitlab.gnome.org/GNOME/epiphany/issues/545
(cherry picked from commit 2d6027d9051a3703f4297c43a831ec69f7f8b125)
-rw-r--r-- | lib/ephy-time-helpers.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/lib/ephy-time-helpers.c b/lib/ephy-time-helpers.c index d3bb85f9f..060833f20 100644 --- a/lib/ephy-time-helpers.c +++ b/lib/ephy-time-helpers.c @@ -67,10 +67,11 @@ char * eel_strdup_strftime (const char *format, struct tm *time_pieces) { - GString *string; + g_autoptr(GString) string = NULL; const char *remainder, *percent; char code[4], buffer[512]; - char *piece, *result, *converted; + char *piece, *result; + g_autofree gchar *converted = NULL; size_t string_length; gboolean strip_leading_zeros, turn_leading_zeros_to_spaces; char modifier; @@ -79,13 +80,14 @@ eel_strdup_strftime (const char *format, struct tm *time_pieces) /* Format could be translated, and contain UTF-8 chars, * so convert to locale encoding which strftime uses */ converted = g_locale_from_utf8 (format, -1, NULL, NULL, NULL); - g_assert (converted != NULL); + if (!converted) + converted = g_strdup (format); string = g_string_new (""); remainder = converted; /* Walk from % character to % character. */ - for (;; ) { + for (;;) { percent = strchr (remainder, '%'); if (percent == NULL) { g_string_append (string, remainder); @@ -197,9 +199,6 @@ eel_strdup_strftime (const char *format, struct tm *time_pieces) /* Convert the string back into utf-8. */ result = g_locale_to_utf8 (string->str, -1, NULL, NULL, NULL); - g_string_free (string, TRUE); - g_free (converted); - return result; } |