Skip to content

Fix -Wsign-compare and -fanalyzer compiler warnings

Ghost User requested to merge (removed):warnings into master

One of the patches in this merge request fixes a curious compiler warning reported by GCC 10.2.0 with -fanalyzer in CFLAGS saying that the value returned by info_cleanup() can potentially be NULL:

/home/atom/local/xfce/libxfce4ui-about/xfce4-about/system-info.c: In function 'get_gpu_info':
/home/atom/local/xfce/libxfce4ui-about/xfce4-about/system-info.c:456:22: warning: use of NULL 's_127' where non-null expected [CWE-690] [-Wanalyzer-null-argument]
  456 |             length = strlen (renderer);
      |                      ^
  'get_gpu_info': events 1-12
    |
    |  392 | get_gpu_info (guint *num_gpus)
    |      | ^
    |      | |
    |      | (1) entry to 'get_gpu_info'
    |......
    |  405 |   if (dpy)
    |      |      ~
    |      |      |
    |      |      (2) following 'true' branch (when 'dpy_93' is non-NULL)...
    |  406 |   {
    |  407 |     XVisualInfo *visual_info;
    |      |     ~
    |      |     |
    |      |     (3) ...to here
    |......
    |  418 |     if (visual_info)
    |      |        ~
    |      |        |
    |      |        (4) following 'true' branch (when 'visual_info_103' is non-NULL)...
    |  419 |     {
    |  420 |       const int screen = DefaultScreen (dpy);
    |      |       ~
    |      |       |
    |      |       (5) ...to here
    |......
    |  437 |       if (ctx)
    |      |          ~
    |      |          |
    |      |          (6) following 'true' branch (when 'ctx_112' is non-NULL)...
    |  438 |       {
    |  439 |  if (glXMakeCurrent (dpy, win, ctx))
    |      |  ~  ~
    |      |  |  |
    |      |  |  (8) following 'true' branch...
    |      |  (7) ...to here
    |  440 |         {
    |  441 |           GPUInfo *gpu = g_new0 (GPUInfo, 1);
    |      |           ~
    |      |           |
    |      |           (9) ...to here
    |......
    |  447 |           if (renderer) {
    |      |              ~
    |      |              |
    |      |              (10) following 'true' branch (when 'renderer_122' is non-NULL)...
    |  448 |             gsize length = strlen (renderer);
    |      |             ~
    |      |             |
    |      |             (11) ...to here
    |......
    |  453 |             s = info_cleanup (renderer);
    |      |                 ~
    |      |                 |
    |      |                 (12) calling 'info_cleanup' from 'get_gpu_info'
    |
    +--> 'info_cleanup': events 13-14
           |
           |  179 | info_cleanup (const char *input)
           |      | ^
           |      | |
           |      | (13) entry to 'info_cleanup'
           |......
           |  183 |   pretty = prettify_info (input);
           |      |            ~
           |      |            |
           |      |            (14) calling 'prettify_info' from 'info_cleanup'
           |
           +--> 'prettify_info': events 15-17
                  |
                  |   81 | prettify_info (const char *info)
                  |      | ^
                  |      | |
                  |      | (15) entry to 'prettify_info'
                  |......
                  |   84 |   g_autofree gchar *pretty = NULL;
                  |      |                     ~
                  |      |                     |
                  |      |                     (17) ...to here
                  |......
                  |  102 |   if (*info == '\0')
                  |      |      ~
                  |      |      |
                  |      |      (16) following 'true' branch...
                  |
           <------+
           |
         'info_cleanup': events 18-19
           |
           |  183 |   pretty = prettify_info (input);
           |      |            ^
           |      |            |
           |      |            (18) returning to 'info_cleanup' from 'prettify_info'
           |  184 |   return remove_duplicate_whitespace (pretty);
           |      |          ~  
           |      |          |
           |      |          (19) calling 'remove_duplicate_whitespace' from 'info_cleanup'
           |
           +--> 'remove_duplicate_whitespace': events 20-22
                  |
                  |  145 | remove_duplicate_whitespace (const char *old)
                  |      | ^
                  |      | |
                  |      | (20) entry to 'remove_duplicate_whitespace'
                  |......
                  |  149 |   g_autoptr(GError) error = NULL;
                  |      |                     ~
                  |      |                     |
                  |      |                     (22) ...to here
                  |  150 | 
                  |  151 |   if (old == NULL)
                  |      |      ~
                  |      |      |
                  |      |      (21) following 'true' branch (when 'old_13(D)' is NULL)...
                  |
           <------+
           |
         'info_cleanup': events 23-24
           |
           |  184 |   return remove_duplicate_whitespace (pretty);
           |      |          ^
           |      |          |
           |      |          (23) returning to 'info_cleanup' from 'remove_duplicate_whitespace'
           |      |          (24) '<anonymous>' is NULL
           |
    <------+
    |
  'get_gpu_info': events 25-26
    |
    |  453 |             s = info_cleanup (renderer);
    |      |                 ^
    |      |                 |
    |      |                 (25) returning to 'get_gpu_info' from 'info_cleanup'
    |......
    |  456 |             length = strlen (renderer);
    |      |                      ~
    |      |                      |
    |      |                      (26) argument 1 ('s_127') NULL where non-null expected
    |
/usr/include/string.h:391:15: note: argument 1 of 'strlen' must be non-null
  391 | extern size_t strlen (const char *__s)
      |               ^
Edited by Ghost User

Merge request reports