[gnome-initial-setup/wip/wjt/ci-f36] um-utils: Remove incorrect NULL check



commit ecb3cd90d16f269d5e1f076ed0c313bbd3441ff1
Author: Will Thompson <wjt endlessos org>
Date:   Fri May 27 20:22:20 2022 +0100

    um-utils: Remove incorrect NULL check
    
    g_utf8_next_char(p) returns a pointer to the next UTF-8 character in the
    given string. This is always p + n for a small constant n.
    
    Assuming p points to a well-formed, 0-byte-terminated UTF-8 string, p +
    n is always non-NULL. And GCC warns about this:
    
        ../gnome-initial-setup/pages/account/um-utils.c: In function 'extract_initials_from_name':
        ../gnome-initial-setup/pages/account/um-utils.c:520:47: error: the comparison will always evaluate as 
'true' for the pointer operand in 'p + (sizetype)*(g_utf8_skip + (sizetype)*(const guchar *)p)' must not be 
NULL [-Werror=address]
          520 |         if (p != NULL && g_utf8_next_char (p) != NULL) {
    
    I think the intention here is to check if *(g_utf8_next_char(p)) is not
    (char) 0. This is guaranteed by the use of g_strstrip() above: the
    string does not end with whitespace. But it also wouldn't matter if it
    were: g_string_append_unichar (initials, 0) would just append a
    redundant NUL terminator.
    
    Remove the unnecessary check.

 gnome-initial-setup/pages/account/um-utils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
---
diff --git a/gnome-initial-setup/pages/account/um-utils.c b/gnome-initial-setup/pages/account/um-utils.c
index 7ffa1dcc..c7cbad10 100644
--- a/gnome-initial-setup/pages/account/um-utils.c
+++ b/gnome-initial-setup/pages/account/um-utils.c
@@ -517,7 +517,7 @@ extract_initials_from_name (const gchar *name)
         g_string_append_unichar (initials, unichar);
 
         p = g_utf8_strrchr (normalized, -1, ' ');
-        if (p != NULL && g_utf8_next_char (p) != NULL) {
+        if (p != NULL) {
                 p = g_utf8_next_char (p);
 
                 unichar = g_utf8_get_char (p);


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