Bug Summary

File:test/cafekbd-keyboard-drawing-test.c
Warning:line 199, column 3
This statement is never executed

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 cafekbd-keyboard-drawing-test.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 -pic-is-pie -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 -fdebug-compilation-dir=/rootdir/test -fcoverage-compilation-dir=/rootdir/test -resource-dir /usr/lib/llvm-19/lib/clang/19 -D HAVE_CONFIG_H -I . -I .. -I .. -I /usr/include/ctk-3.0 -I /usr/include/pango-1.0 -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/harfbuzz -I /usr/include/freetype2 -I /usr/include/libpng16 -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/fribidi -I /usr/include/cairo -I /usr/include/pixman-1 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/x86_64-linux-gnu -I /usr/include/webp -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/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/sysprof-6 -I /usr/include/libxml2 -D CAFELOCALEDIR="/usr/share/locale" -internal-isystem /usr/lib/llvm-19/lib/clang/19/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -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.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/2025-02-06-152034-14522-1 -x c cafekbd-keyboard-drawing-test.c
1/*
2 * Copyright (C) 2006 Sergey V. Udaltsov <svu@gnome.org>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20#if HAVE_CONFIG_H1
21# include <config.h>
22#endif
23
24#include <ctk/ctk.h>
25#include <stdlib.h>
26#include <string.h>
27#include <glib.h>
28#include "libcafekbd/cafekbd-keyboard-drawing.h"
29
30
31static gchar *groups = NULL((void*)0);
32static gchar *levels = NULL((void*)0);
33static gchar *symbols = NULL((void*)0);
34static gchar *keycodes = NULL((void*)0);
35static gchar *geometry = NULL((void*)0);
36
37static gboolean track_config = FALSE(0);
38static gboolean track_modifiers = FALSE(0);
39static gboolean program_version = FALSE(0);
40
41static const GOptionEntry options[] = {
42 {"groups", '\0', 0, G_OPTION_ARG_STRING, &groups,
43 "Keyboard groups to display, from 1-4. Up to four groups only may be "
44 "displayed. Examples: --groups=3 or --groups=1,2,1,2",
45 "group1[,group2[,group3[,group4]]]"},
46 {"levels", '\0', 0, G_OPTION_ARG_STRING, &levels,
47 "Keyboard shift levels to display, from 1-64. Up to four shift levels "
48 "only may be displayed. Examples: --levels=3 or --levels=1,2,1,2",
49 "level1[,level2[,level3[,level4]]]"},
50 {"symbols", '\0', 0, G_OPTION_ARG_STRING, &symbols,
51 "Symbols component of the keyboard. If you omit this option, it is "
52 "obtained from the X server; that is, the keyboard that is currently "
53 "configured is drawn. Examples: --symbols=us or "
54 "--symbols=us(pc104)+iso9995-3+group(switch)+ctrl(nocaps)", NULL((void*)0)},
55 {"keycodes", '\0', 0, G_OPTION_ARG_STRING, &keycodes,
56 "Keycodes component of the keyboard. If you omit this option, it is "
57 "obtained from the X server; that is, the keyboard that is currently"
58 " configured is drawn. Examples: --keycodes=xfree86+aliases(qwerty)",
59 NULL((void*)0)},
60 {"geometry", '\0', 0, G_OPTION_ARG_STRING, &geometry,
61 "Geometry xkb component. If you omit this option, it is obtained from the"
62 " X server; that is, the keyboard that is currently configured is drawn. "
63 "Example: --geometry=kinesis", NULL((void*)0)},
64 {"track-modifiers", '\0', 0, G_OPTION_ARG_NONE, &track_modifiers,
65 "Track the current modifiers", NULL((void*)0)},
66 {"track-config", '\0', 0, G_OPTION_ARG_NONE, &track_config,
67 "Track the server XKB configuration", NULL((void*)0)},
68 {"version", '\0', 0, G_OPTION_ARG_NONE, &program_version,
69 "Show current version", NULL((void*)0)},
70 {NULL((void*)0)},
71};
72
73static gboolean
74set_groups (gchar * groups_option,
75 CafekbdKeyboardDrawingGroupLevel * groupLevels)
76{
77 CafekbdKeyboardDrawingGroupLevel *pgl = groupLevels;
78 gint cntr, g;
79
80 groupLevels[0].group =
81 groupLevels[1].group =
82 groupLevels[2].group = groupLevels[3].group = -1;
83
84 if (groups_option == NULL((void*)0))
85 return TRUE(!(0));
86
87 for (cntr = 4; --cntr >= 0;) {
88 if (*groups_option == '\0')
89 return FALSE(0);
90
91 g = *groups_option - '1';
92 if (g < 0 || g >= 4)
93 return FALSE(0);
94
95 pgl->group = g;
96 /* printf ("group %d\n", pgl->group); */
97
98 groups_option++;
99 if (*groups_option == '\0')
100 return TRUE(!(0));
101 if (*groups_option != ',')
102 return FALSE(0);
103
104 groups_option++;
105 pgl++;
106 }
107
108 return TRUE(!(0));
109}
110
111static gboolean
112set_levels (gchar * levels_option,
113 CafekbdKeyboardDrawingGroupLevel * groupLevels)
114{
115 CafekbdKeyboardDrawingGroupLevel *pgl = groupLevels;
116 gint cntr, l;
117 gchar *p;
118
119 groupLevels[0].level =
120 groupLevels[1].level =
121 groupLevels[2].level = groupLevels[3].level = -1;
122
123 if (levels_option == NULL((void*)0))
124 return TRUE(!(0));
125
126 for (cntr = 4; --cntr >= 0;) {
127 if (*levels_option == '\0')
128 return FALSE(0);
129
130 l = (gint) strtol (levels_option, &p, 10) - 1;
131 if (l < 0 || l >= 64)
132 return FALSE(0);
133
134 pgl->level = l;
135 /* printf ("level %d\n", pgl->level); */
136
137 levels_option = p;
138 if (*levels_option == '\0')
139 return TRUE(!(0));
140 if (*levels_option != ',')
141 return FALSE(0);
142
143 levels_option++;
144 pgl++;
145 }
146
147 return TRUE(!(0));
148}
149
150static void
151bad_keycode (CafekbdKeyboardDrawing *drawing G_GNUC_UNUSED__attribute__ ((__unused__)),
152 guint keycode)
153{
154 g_warning
155 ("got keycode %u, which is not on your keyboard according to your configuration",
156 keycode);
157}
158
159gint
160main (gint argc, gchar ** argv)
161{
162 CtkWidget *window;
163 CtkWidget *cafekbd_keyboard_drawing;
164 CdkScreen *screen;
165 CdkMonitor *monitor;
166 CdkRectangle rect;
167 GOptionContext *context;
168 GError *error = NULL((void*)0);
169
170 CafekbdKeyboardDrawingGroupLevel groupLevels[4] =
171 { {0, 0}, {1, 0}, {0, 1}, {1, 1} };
172 CafekbdKeyboardDrawingGroupLevel *pgroupLevels[4] =
173 { &groupLevels[0], &groupLevels[1], &groupLevels[2],
174 &groupLevels[3]
175 };
176
177 context = g_option_context_new ("kbdraw");
178 g_option_context_add_main_entries (context, options, NULL((void*)0));
179 if (!g_option_context_parse (context, &argc, &argv, &error)) {
180 g_message ("option parsing failed: %s", error->message);
181 g_option_context_free (context);
182 exit (EXIT_FAILURE1);
183 }
184 g_option_context_free (context);
185
186 if (program_version) {
187 g_print ("kbdraw %s\n", VERSION"1.25.0");
188 exit (0);
189 }
190
191 ctk_init (&argc, &argv);
192
193 if (!set_groups (groups, groupLevels)) {
194 g_printerr ("--groups: invalid argument\n");
195 exit (1);
196 }
197
198 if (!set_levels (levels, groupLevels)) {
199 g_printerr ("--levels: invalid argument\n");
This statement is never executed
200 exit (1);
201 }
202
203 window = ctk_window_new (CTK_WINDOW_TOPLEVEL);
204 g_signal_connect (G_OBJECT (window), "destroy",g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((window)), (((GType) ((20) << (2)))
)))))), ("destroy"), (((GCallback) (ctk_main_quit))), (((void
*)0)), ((void*)0), (GConnectFlags) 0)
205 G_CALLBACK (ctk_main_quit), NULL)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((window)), (((GType) ((20) << (2)))
)))))), ("destroy"), (((GCallback) (ctk_main_quit))), (((void
*)0)), ((void*)0), (GConnectFlags) 0)
;
206
207 screen = ctk_window_get_screen (CTK_WINDOW (window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_window_get_type ()))))))
);
208 monitor = cdk_display_get_monitor_at_point (cdk_screen_get_display (screen), 0, 0);
209 cdk_monitor_get_geometry (monitor, &rect);
210 ctk_window_set_default_size (CTK_WINDOW (window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_window_get_type ()))))))
,
211 rect.width * 4 / 5,
212 rect.height * 1 / 2);
213
214 ctk_widget_show (window);
215
216 cafekbd_keyboard_drawing = cafekbd_keyboard_drawing_new ();
217 ctk_widget_show (cafekbd_keyboard_drawing);
218 ctk_container_add (CTK_CONTAINER (window)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_container_get_type ()))))))
, cafekbd_keyboard_drawing);
219
220 cafekbd_keyboard_drawing_set_groups_levels (CAFEKBD_KEYBOARD_DRAWING((((CafekbdKeyboardDrawing*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((cafekbd_keyboard_drawing)), (cafekbd_keyboard_drawing_get_type
())))))
221 (cafekbd_keyboard_drawing)((((CafekbdKeyboardDrawing*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((cafekbd_keyboard_drawing)), (cafekbd_keyboard_drawing_get_type
())))))
,
222 pgroupLevels);
223
224 if (track_modifiers)
225 cafekbd_keyboard_drawing_set_track_modifiers
226 (CAFEKBD_KEYBOARD_DRAWING (cafekbd_keyboard_drawing)((((CafekbdKeyboardDrawing*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((cafekbd_keyboard_drawing)), (cafekbd_keyboard_drawing_get_type
())))))
, TRUE(!(0)));
227 if (track_config)
228 cafekbd_keyboard_drawing_set_track_config
229 (CAFEKBD_KEYBOARD_DRAWING (cafekbd_keyboard_drawing)((((CafekbdKeyboardDrawing*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((cafekbd_keyboard_drawing)), (cafekbd_keyboard_drawing_get_type
())))))
, TRUE(!(0)));
230 g_signal_connect (G_OBJECT (cafekbd_keyboard_drawing), "bad-keycode",g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((cafekbd_keyboard_drawing)), (((GType) ((
20) << (2))))))))), ("bad-keycode"), (((GCallback) (bad_keycode
))), (((void*)0)), ((void*)0), (GConnectFlags) 0)
231 G_CALLBACK (bad_keycode), NULL)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((cafekbd_keyboard_drawing)), (((GType) ((
20) << (2))))))))), ("bad-keycode"), (((GCallback) (bad_keycode
))), (((void*)0)), ((void*)0), (GConnectFlags) 0)
;
232
233 if (symbols || geometry || keycodes) {
234 XkbComponentNamesRec names;
235 gint success;
236
237 memset (&names, '\0', sizeof (names));
238
239 if (symbols)
240 names.symbols = symbols;
241 else
242 names.symbols = (gchar *)
243 cafekbd_keyboard_drawing_get_symbols
244 (CAFEKBD_KEYBOARD_DRAWING((((CafekbdKeyboardDrawing*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((cafekbd_keyboard_drawing)), (cafekbd_keyboard_drawing_get_type
())))))
245 (cafekbd_keyboard_drawing)((((CafekbdKeyboardDrawing*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((cafekbd_keyboard_drawing)), (cafekbd_keyboard_drawing_get_type
())))))
);
246
247 if (keycodes)
248 names.keycodes = keycodes;
249 else
250 names.keycodes = (gchar *)
251 cafekbd_keyboard_drawing_get_keycodes
252 (CAFEKBD_KEYBOARD_DRAWING((((CafekbdKeyboardDrawing*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((cafekbd_keyboard_drawing)), (cafekbd_keyboard_drawing_get_type
())))))
253 (cafekbd_keyboard_drawing)((((CafekbdKeyboardDrawing*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((cafekbd_keyboard_drawing)), (cafekbd_keyboard_drawing_get_type
())))))
);
254
255 if (geometry)
256 names.geometry = geometry;
257 else
258 names.geometry = (gchar *)
259 cafekbd_keyboard_drawing_get_geometry
260 (CAFEKBD_KEYBOARD_DRAWING((((CafekbdKeyboardDrawing*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((cafekbd_keyboard_drawing)), (cafekbd_keyboard_drawing_get_type
())))))
261 (cafekbd_keyboard_drawing)((((CafekbdKeyboardDrawing*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((cafekbd_keyboard_drawing)), (cafekbd_keyboard_drawing_get_type
())))))
);
262
263 success =
264 cafekbd_keyboard_drawing_set_keyboard
265 (CAFEKBD_KEYBOARD_DRAWING (cafekbd_keyboard_drawing)((((CafekbdKeyboardDrawing*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((cafekbd_keyboard_drawing)), (cafekbd_keyboard_drawing_get_type
())))))
,
266 &names);
267 if (!success) {
268 g_printerr
269 ("\nError loading new keyboard description with components:\n\n"
270 " keycodes: %s\n" " types: %s\n"
271 " compat: %s\n" " symbols: %s\n"
272 " geometry: %s\n\n", names.keycodes,
273 names.types, names.compat, names.symbols,
274 names.geometry);
275 exit (1);
276 }
277 }
278
279 ctk_widget_grab_focus (cafekbd_keyboard_drawing);
280
281 ctk_main ();
282
283 return 0;
284}