Bug Summary

File:cafe-panel/libpanel-util/panel-glib.c
Warning:line 146, column 10
The right operand of '==' is a garbage value

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name panel-glib.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/rootdir/cafe-panel/libpanel-util -resource-dir /usr/lib/llvm-16/lib/clang/16 -D HAVE_CONFIG_H -I . -I ../.. -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/sysprof-6 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/libpng16 -I /usr/include/x86_64-linux-gnu -I /usr/include/webp -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/pango-1.0 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/fribidi -I /usr/include/cairo -I /usr/include/pixman-1 -I /usr/include/ctk-3.0 -I /usr/include/gio-unix-2.0 -I /usr/include/atk-1.0 -I /usr/include/at-spi2-atk/2.0 -I /usr/include/at-spi-2.0 -I /usr/include/dbus-1.0 -I /usr/lib/x86_64-linux-gnu/dbus-1.0/include -I /usr/include/cafe-desktop-2.0 -I /usr/include/startup-notification-1.0 -I /usr/include/dconf -I /usr/include/cafe-menus -I /usr/include/dconf -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/sysprof-6 -I /usr/include/libmount -I /usr/include/blkid -I . -I . -I ../../cafe-panel/libpanel-util -D DATADIR="/usr/share" -D PIC -internal-isystem /usr/lib/llvm-16/lib/clang/16/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir=/rootdir/cafe-panel/libpanel-util -ferror-limit 19 -fgnuc-version=4.2.1 -analyzer-checker deadcode.DeadStores -analyzer-checker alpha.deadcode.UnreachableCode -analyzer-checker alpha.core.CastSize -analyzer-checker alpha.core.CastToStruct -analyzer-checker alpha.core.IdenticalExpr -analyzer-checker alpha.core.SizeofPtr -analyzer-checker alpha.security.ArrayBoundV2 -analyzer-checker alpha.security.MallocOverflow -analyzer-checker alpha.security.ReturnPtrRange -analyzer-checker alpha.unix.SimpleStream -analyzer-checker alpha.unix.cstring.BufferOverlap -analyzer-checker alpha.unix.cstring.NotNullTerminated -analyzer-checker alpha.unix.cstring.OutOfBounds -analyzer-checker alpha.core.FixedAddr -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /rootdir/html-report/2024-08-06-121451-55967-1 -x c panel-glib.c
1/*
2 * panel-glib.c: various small extensions to glib
3 *
4 * Copyright (C) 2008 Novell, Inc.
5 *
6 * Originally based on code from panel-util.c (there was no relevant copyright
7 * header at the time), but the code was:
8 * Copyright (C) Novell, Inc. (for the panel_g_utf8_strstrcase() code)
9 * Copyright (C) Dennis Cranston (for the panel_g_lookup_in_data_dirs() code)
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of the
14 * License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24 * 02110-1301, USA.
25 *
26 * Authors:
27 * Vincent Untz <vuntz@gnome.org>
28 */
29
30#include <string.h>
31
32#include <glib.h>
33
34#include "panel-glib.h"
35
36typedef char * (*LookupInDir) (const char *basename, const char *dir);
37
38static char *
39_lookup_in_dir (const char *basename,
40 const char *dir)
41{
42 char *path;
43
44 path = g_build_filename (dir, basename, NULL((void*)0));
45 if (!g_file_test (path, G_FILE_TEST_EXISTS)) {
46 g_free (path);
47 return NULL((void*)0);
48 }
49
50 return path;
51}
52
53static char *
54_lookup_in_applications_subdir (const char *basename,
55 const char *dir)
56{
57 char *path;
58
59 path = g_build_filename (dir, "applications", basename, NULL((void*)0));
60 if (!g_file_test (path, G_FILE_TEST_EXISTS)) {
61 g_free (path);
62 return NULL((void*)0);
63 }
64
65 return path;
66}
67
68static char *
69_panel_g_lookup_in_data_dirs_internal (const char *basename,
70 LookupInDir lookup)
71{
72 const char * const *system_data_dirs;
73 const char *user_data_dir;
74 char *retval;
75 int i;
76
77 user_data_dir = g_get_user_data_dir ();
78 system_data_dirs = g_get_system_data_dirs ();
79
80 if ((retval = lookup (basename, user_data_dir)))
81 return retval;
82
83 for (i = 0; system_data_dirs[i]; i++)
84 if ((retval = lookup (basename, system_data_dirs[i])))
85 return retval;
86
87 return NULL((void*)0);
88}
89
90char *
91panel_g_lookup_in_data_dirs (const char *basename)
92{
93 return _panel_g_lookup_in_data_dirs_internal (basename,
94 _lookup_in_dir);
95}
96
97char *
98panel_g_lookup_in_applications_dirs (const char *basename)
99{
100 return _panel_g_lookup_in_data_dirs_internal (basename,
101 _lookup_in_applications_subdir);
102}
103
104/* Copied from evolution-data-server/libedataserver/e-util.c:
105 * e_util_unicode_get_utf8() */
106static char *
107_unicode_get_utf8 (const char *text, gunichar *out)
108{
109 *out = g_utf8_get_char (text);
17
Value assigned to 'unival', which participates in a condition later
110 return (*out == (gunichar)-1) ? NULL((void*)0) : g_utf8_next_char (text)(char *)((text) + g_utf8_skip[*(const guchar *)(text)]);
10
Assuming the condition is false
11
'?' condition is false
12
Returning pointer, which participates in a condition later
18
Assuming the condition is false
19
'?' condition is false
20
Returning pointer, which participates in a condition later
111}
112
113/* Copied from evolution-data-server/libedataserver/e-util.c:
114 * e_util_utf8_strstrcase() */
115const char *
116panel_g_utf8_strstrcase (const char *haystack, const char *needle)
117{
118 gunichar *nuni;
119 gunichar unival;
120 gint nlen;
121 const char *o, *p;
122
123 if (haystack == NULL((void*)0)) return NULL((void*)0);
1
Assuming 'haystack' is not equal to NULL
2
Taking false branch
124 if (needle == NULL((void*)0)) return NULL((void*)0);
3
Assuming 'needle' is not equal to NULL
4
Taking false branch
125 if (strlen (needle) == 0) return haystack;
5
Assuming the condition is false
6
Taking false branch
126 if (strlen (haystack) == 0) return NULL((void*)0);
7
Assuming the condition is false
8
Taking false branch
127
128 nuni = g_alloca (sizeof (gunichar) * strlen (needle))__builtin_alloca (sizeof (gunichar) * strlen (needle));
129
130 nlen = 0;
131 for (p = _unicode_get_utf8 (needle, &unival);
9
Calling '_unicode_get_utf8'
13
Returning from '_unicode_get_utf8'
14
Loop condition is false. Execution continues on line 137
132 p
13.1
'p' is non-null
&& unival;
133 p = _unicode_get_utf8 (p, &unival)) {
134 nuni[nlen++] = g_unichar_tolower (unival);
135 }
136 /* NULL means there was illegal utf-8 sequence */
137 if (!p
14.1
'p' is non-null
) return NULL((void*)0);
15
Taking false branch
138
139 o = haystack;
140 for (p = _unicode_get_utf8 (o, &unival);
16
Calling '_unicode_get_utf8'
21
Returning from '_unicode_get_utf8'
22
Loop condition is true. Entering loop body
141 p
21.1
'p' is non-null
&& unival;
142 p = _unicode_get_utf8 (p, &unival)) {
143 gint sc;
144 sc = g_unichar_tolower (unival);
145 /* We have valid stripped char */
146 if (sc == nuni[0]) {
23
The right operand of '==' is a garbage value
147 const char *q = p;
148 gint npos = 1;
149 while (npos < nlen) {
150 q = _unicode_get_utf8 (q, &unival);
151 if (!q || !unival) return NULL((void*)0);
152 sc = g_unichar_tolower (unival);
153 if (sc != nuni[npos]) break;
154 npos++;
155 }
156 if (npos == nlen) {
157 return o;
158 }
159 }
160 o = p;
161 }
162
163 return NULL((void*)0);
164}