[epiphany] Fix segfaulting eel_strdup_strftime ()



commit 2d6027d9051a3703f4297c43a831ec69f7f8b125
Author: Jan-Michael Brummer <jan brummer tabos org>
Date:   Fri May 3 14:55:37 2019 +0200

    Fix segfaulting eel_strdup_strftime ()
    
    Fixes: https://gitlab.gnome.org/GNOME/epiphany/issues/545

 lib/ephy-time-helpers.c | 13 ++++++-------
 1 file 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;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]