[libadwaita/libadwaita-1-0] avatar: fix invalid UTF-8 iteration



commit 2ae1934edb3dce7a70242da270307244e96f9bdf
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.
    
    
    (cherry picked from commit 9874715bc34b2c2880efb43265788f94567aa367)

 src/adw-avatar.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
---
diff --git a/src/adw-avatar.c b/src/adw-avatar.c
index dec89921..88cbecf3 100644
--- a/src/adw-avatar.c
+++ b/src/adw-avatar.c
@@ -97,11 +97,11 @@ extract_initials_from_text (const char *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]