Formalize buffer var allocations
[profile/ivi/org.tizen.video-player.git] / src / hb-glib.cc
index 6174498..76e1dfd 100644 (file)
@@ -244,6 +244,9 @@ hb_glib_unicode_compose (hb_unicode_funcs_t *ufuncs HB_UNUSED,
   /* We don't ifdef-out the fallback code such that compiler always
    * sees it and makes sure it's compilable. */
 
+  if (!a || !b)
+    return FALSE;
+
   gchar utf8[12];
   gchar *normalized;
   gint len;
@@ -295,6 +298,16 @@ hb_glib_unicode_decompose (hb_unicode_funcs_t *ufuncs HB_UNUSED,
   } else if (len == 2) {
     *a = g_utf8_get_char (normalized);
     *b = g_utf8_get_char (g_utf8_next_char (normalized));
+    /* Here's the ugly part: if ab decomposes to a single character and
+     * that character decomposes again, we have to detect that and undo
+     * the second part :-(. */
+    gchar *recomposed = g_utf8_normalize (normalized, -1, G_NORMALIZE_NFC);
+    hb_codepoint_t c = g_utf8_get_char (recomposed);
+    if (c != ab && c != *a) {
+      *a = c;
+      *b = 0;
+    }
+    g_free (recomposed);
     ret = TRUE;
   } else {
     /* If decomposed to more than two characters, take the last one,