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
This commit is contained in:
Cosimo Cecchi
2017-04-01 17:23:19 -07:00
parent 62edcf03d3
commit 6e192588e0

View File

@@ -2210,11 +2210,12 @@ format_ampm (GDateTime *datetime,
gboolean locale_is_utf8, gboolean locale_is_utf8,
gboolean uppercase) gboolean uppercase)
{ {
gchar *ampm; const gchar *ampm;
gchar *tmp; gchar *tmp, *ampm_dup;
gsize tmp_len; gsize len;
ampm = GET_AMPM (datetime);
ampm = (gchar *) GET_AMPM (datetime);
#if defined (HAVE_LANGINFO_TIME) #if defined (HAVE_LANGINFO_TIME)
if (!locale_is_utf8) if (!locale_is_utf8)
{ {
@@ -2225,23 +2226,23 @@ format_ampm (GDateTime *datetime,
} }
#endif #endif
if (uppercase) if (uppercase)
ampm = g_utf8_strup (ampm, -1); ampm_dup = g_utf8_strup (ampm, -1);
else else
ampm = g_utf8_strdown (ampm, -1); ampm_dup = g_utf8_strdown (ampm, -1);
tmp_len = strlen (ampm); len = strlen (ampm_dup);
if (!locale_is_utf8) if (!locale_is_utf8)
{ {
#if defined (HAVE_LANGINFO_TIME) #if defined (HAVE_LANGINFO_TIME)
g_free (tmp); g_free (tmp);
#endif #endif
tmp = g_locale_from_utf8 (ampm, -1, NULL, &tmp_len, NULL); tmp = g_locale_from_utf8 (ampm_dup, -1, NULL, &len, NULL);
g_free (ampm); g_free (ampm_dup);
if (!tmp) if (!tmp)
return FALSE; return FALSE;
ampm = tmp; ampm_dup = tmp;
} }
g_string_append_len (outstr, ampm, tmp_len); g_string_append_len (outstr, ampm_dup, len);
g_free (ampm); g_free (ampm_dup);
return TRUE; return TRUE;
} }