[libhandy/wip/exalm/rc: 1/2] avatar: fix invalid UTF-8 iteration




commit d82c031896fd0f1d7149d2af7cf04e6e45279951
Author: Christian Hergert <chergert redhat com>
Date:   Wed Feb 16 14:08:11 2022 -0800

    avatar: fix invalid UTF-8 iteration
    
    This branch doesn't do what it looks like it is because g_utf8_next_char()
    will always return a pointer if q is valid (it just might dereference to
    \0 if it's at the end of the string).
    
    Instead, just allow dereference to the trailing \0 byte and check for a
    non-zero unichar.

 src/hdy-avatar.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
---
diff --git a/src/hdy-avatar.c b/src/hdy-avatar.c
index 7ca4ff48..d4e0d01d 100644
--- a/src/hdy-avatar.c
+++ b/src/hdy-avatar.c
@@ -149,11 +149,11 @@ extract_initials_from_text (const gchar *text)
   g_string_append_unichar (initials, unichar);
 
   q = g_utf8_strrchr (normalized, -1, ' ');
-  if (q != NULL && g_utf8_next_char (q) != NULL) {
-    q = g_utf8_next_char (q);
+  if (q != NULL) {
+    unichar = g_utf8_get_char (g_utf8_next_char (q));
 
-    unichar = g_utf8_get_char (q);
-    g_string_append_unichar (initials, unichar);
+    if (unichar != 0)
+      g_string_append_unichar (initials, unichar);
   }
 
   return g_string_free (initials, FALSE);


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