[libadwaita/wip/chergert/fix-avatar-gcc-warning] avatar: fix invalid UTF-8 iteration
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libadwaita/wip/chergert/fix-avatar-gcc-warning] avatar: fix invalid UTF-8 iteration
- Date: Wed, 16 Feb 2022 22:09:01 +0000 (UTC)
commit 9874715bc34b2c2880efb43265788f94567aa367
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/adw-avatar.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
---
diff --git a/src/adw-avatar.c b/src/adw-avatar.c
index 6e706502..f657bb58 100644
--- a/src/adw-avatar.c
+++ b/src/adw-avatar.c
@@ -99,11 +99,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);
}
g_free (normalized);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]