[glib] datetime: don't conflate heap/non-heap allocations in same variable



commit 6e192588e06b0da345486ed3bc467b4bff269f22
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Sat Apr 1 17:23:19 2017 -0700

    datetime: don't conflate heap/non-heap allocations in same variable
    
    Use an extra variable instead of casting out the const specifier.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=761889

 glib/gdatetime.c |   25 +++++++++++++------------
 1 files changed, 13 insertions(+), 12 deletions(-)
---
diff --git a/glib/gdatetime.c b/glib/gdatetime.c
index 0bb5cbc..5211c14 100644
--- a/glib/gdatetime.c
+++ b/glib/gdatetime.c
@@ -2210,11 +2210,12 @@ format_ampm (GDateTime *datetime,
              gboolean   locale_is_utf8,
              gboolean   uppercase)
 {
-  gchar    *ampm;
-  gchar    *tmp;
-  gsize     tmp_len;
+  const gchar *ampm;
+  gchar       *tmp, *ampm_dup;
+  gsize        len;
+
+  ampm = GET_AMPM (datetime);
 
-  ampm = (gchar *) GET_AMPM (datetime);
 #if defined (HAVE_LANGINFO_TIME)
   if (!locale_is_utf8)
     {
@@ -2225,23 +2226,23 @@ format_ampm (GDateTime *datetime,
     }
 #endif
   if (uppercase)
-    ampm = g_utf8_strup (ampm, -1);
+    ampm_dup = g_utf8_strup (ampm, -1);
   else
-    ampm = g_utf8_strdown (ampm, -1);
-  tmp_len = strlen (ampm);
+    ampm_dup = g_utf8_strdown (ampm, -1);
+  len = strlen (ampm_dup);
   if (!locale_is_utf8)
     {
 #if defined (HAVE_LANGINFO_TIME)
       g_free (tmp);
 #endif
-      tmp = g_locale_from_utf8 (ampm, -1, NULL, &tmp_len, NULL);
-      g_free (ampm);
+      tmp = g_locale_from_utf8 (ampm_dup, -1, NULL, &len, NULL);
+      g_free (ampm_dup);
       if (!tmp)
         return FALSE;
-      ampm = tmp;
+      ampm_dup = tmp;
     }
-  g_string_append_len (outstr, ampm, tmp_len);
-  g_free (ampm);
+  g_string_append_len (outstr, ampm_dup, len);
+  g_free (ampm_dup);
 
   return TRUE;
 }


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