[gnome-characters/gnome-3-16] libgc: Fix match against a character itself



commit 6ecf75bb549e30415bef085a380483892655142b
Author: Daiki Ueno <dueno src gnome org>
Date:   Wed Apr 1 10:30:21 2015 +0900

    libgc: Fix match against a character itself
    
    https://bugzilla.gnome.org/show_bug.cgi?id=747061

 lib/gc.c |   19 ++++++++-----------
 1 files changed, 8 insertions(+), 11 deletions(-)
---
diff --git a/lib/gc.c b/lib/gc.c
index 46498c3..b0ad00c 100644
--- a/lib/gc.c
+++ b/lib/gc.c
@@ -367,22 +367,19 @@ filter_keywords (GcCharacterIter *iter, ucs4_t uc)
   if (!uc_is_print (uc))
     return FALSE;
 
-  /* Match against the character itself.  */
-  if (*keywords)
+  /* Special case if KEYWORDS only contains a single word.  */
+  if (*keywords && *(keywords + 1) == NULL)
     {
+      size_t length = strlen (*keywords);
       uint8_t utf8[6];
-      size_t length = G_N_ELEMENTS (utf8);
+      size_t utf8_length = G_N_ELEMENTS (utf8);
 
-      u32_to_u8 (&uc, 1, utf8, &length);
-      if (length == strlen (*keywords) && memcmp (*keywords, utf8, length) == 0)
+      /* Match against the character itself.  */
+      u32_to_u8 (&uc, 1, utf8, &utf8_length);
+      if (utf8_length == length && memcmp (*keywords, utf8, utf8_length) == 0)
        return TRUE;
-    }
-
-  /* Match against the hexadecimal code point.  */
-  if (*keywords && *(keywords + 1) == NULL)
-    {
-      size_t length = strlen (*keywords);
 
+      /* Match against the hexadecimal code point.  */
       if (length <= 6
          && strspn (*keywords, "0123456789abcdefABCDEF") == length
          && strtoul (*keywords, NULL, 16) == uc)


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