Bug Summary

File:testsuite/reftests/reftest-snapshot.c
Warning:line 219, column 11
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 reftest-snapshot.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 -fdebug-compilation-dir=/rootdir/testsuite/reftests -fcoverage-compilation-dir=/rootdir/testsuite/reftests -resource-dir /usr/lib/llvm-19/lib/clang/19 -D HAVE_CONFIG_H -I . -I ../.. -I ../.. -I ../../cdk -I ../../cdk -D CDK_DISABLE_DEPRECATED -D CTK_DISABLE_DEPRECATED -D G_ENABLE_DEBUG -D G_ENABLE_CONSISTENCY_CHECKS -D GLIB_MIN_REQUIRED_VERSION=GLIB_VERSION_2_66 -D GLIB_MAX_ALLOWED_VERSION=GLIB_VERSION_2_66 -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/atk-1.0 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/x86_64-linux-gnu -I /usr/include/webp -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/gio-unix-2.0 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/libpng16 -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/pango-1.0 -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/fribidi -I /usr/include/cairo -I /usr/include/pixman-1 -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/sysprof-6 -D PIC -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/2024-12-18-231339-43635-1 -x c reftest-snapshot.c
1/*
2 * Copyright (C) 2011 Red Hat Inc.
3 *
4 * Author:
5 * Benjamin Otte <otte@gnome.org>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include "config.h"
22
23#include "reftest-snapshot.h"
24
25#include "reftest-module.h"
26#include "ctk-reftest.h"
27
28#include <string.h>
29
30typedef enum {
31 SNAPSHOT_WINDOW,
32 SNAPSHOT_DRAW
33} SnapshotMode;
34
35static CtkWidget *
36builder_get_toplevel (CtkBuilder *builder)
37{
38 GSList *list, *walk;
39 CtkWidget *window = NULL((void*)0);
40
41 list = ctk_builder_get_objects (builder);
42 for (walk = list; walk; walk = walk->next)
43 {
44 if (CTK_IS_WINDOW (walk->data)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) (
(walk->data)); GType __t = ((ctk_window_get_type ())); gboolean
__r; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; }))))
&&
45 ctk_widget_get_parent (walk->data) == NULL((void*)0))
46 {
47 window = walk->data;
48 break;
49 }
50 }
51
52 g_slist_free (list);
53
54 return window;
55}
56
57static gboolean
58quit_when_idle (gpointer loop)
59{
60 g_main_loop_quit (loop);
61
62 return G_SOURCE_REMOVE(0);
63}
64
65static gint inhibit_count;
66static GMainLoop *loop;
67
68void
69reftest_inhibit_snapshot (void)
70{
71 inhibit_count++;
72}
73
74void
75reftest_uninhibit_snapshot (void)
76{
77 g_assert (inhibit_count > 0)do { if (inhibit_count > 0) ; else g_assertion_message_expr
(((gchar*) 0), "reftest-snapshot.c", 77, ((const char*) (__func__
)), "inhibit_count > 0"); } while (0)
;
78 inhibit_count--;
79
80 if (inhibit_count == 0)
81 g_idle_add (quit_when_idle, loop);
82}
83
84static void
85check_for_draw (CdkEvent *event,
86 gpointer data G_GNUC_UNUSED__attribute__ ((__unused__)))
87{
88 if (event->type == CDK_EXPOSE)
89 {
90 reftest_uninhibit_snapshot ();
91 cdk_event_handler_set ((CdkEventFunc) ctk_main_do_event, NULL((void*)0), NULL((void*)0));
92 }
93
94 ctk_main_do_event (event);
95}
96
97static cairo_surface_t *
98snapshot_widget (CtkWidget *widget, SnapshotMode mode)
99{
100 cairo_surface_t *surface;
101 cairo_pattern_t *bg;
102 cairo_t *cr;
103
104 g_assert (ctk_widget_get_realized (widget))do { if (ctk_widget_get_realized (widget)) ; else g_assertion_message_expr
(((gchar*) 0), "reftest-snapshot.c", 104, ((const char*) (__func__
)), "ctk_widget_get_realized (widget)"); } while (0)
;
105
106 loop = g_main_loop_new (NULL((void*)0), FALSE(0));
107
108 /* We wait until the widget is drawn for the first time.
109 * We can not wait for a CtkWidget::draw event, because that might not
110 * happen if the window is fully obscured by windowed child widgets.
111 * Alternatively, we could wait for an expose event on widget's window.
112 * Both of these are rather hairy, not sure what's best.
113 *
114 * We also use an inhibit mechanism, to give module functions a chance
115 * to delay the snapshot.
116 */
117 reftest_inhibit_snapshot ();
118 cdk_event_handler_set (check_for_draw, NULL((void*)0), NULL((void*)0));
119 g_main_loop_run (loop);
120
121 surface = cdk_window_create_similar_surface (ctk_widget_get_window (widget),
122 CAIRO_CONTENT_COLOR,
123 ctk_widget_get_allocated_width (widget),
124 ctk_widget_get_allocated_height (widget));
125
126 cr = cairo_create (surface);
127
128 switch (mode)
129 {
130 case SNAPSHOT_WINDOW:
131 {
132 CdkWindow *window = ctk_widget_get_window (widget);
133 if (cdk_window_get_window_type (window) == CDK_WINDOW_TOPLEVEL ||
134 cdk_window_get_window_type (window) == CDK_WINDOW_FOREIGN)
135 {
136 /* give the WM/server some time to sync. They need it.
137 * Also, do use popups instead of toplevels in your tests
138 * whenever you can.
139 */
140 cdk_display_sync (cdk_window_get_display (window));
141 g_timeout_add (500, quit_when_idle, loop);
142 g_main_loop_run (loop);
143 }
144 cdk_cairo_set_source_window (cr, window, 0, 0);
145 cairo_paint (cr);
146 }
147 break;
148 case SNAPSHOT_DRAW:
149 bg = cdk_window_get_background_pattern (ctk_widget_get_window (widget));
150 if (bg)
151 {
152 cairo_set_source (cr, bg);
153 cairo_paint (cr);
154 }
155 ctk_widget_draw (widget, cr);
156 break;
157 default:
158 g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "reftest-snapshot.c"
, 158, ((const char*) (__func__)), ((void*)0)); } while (0)
;
159 break;
160 }
161
162 cairo_destroy (cr);
163 g_main_loop_unref (loop);
164 ctk_widget_destroy (widget);
165
166 return surface;
167}
168
169static void
170connect_signals (CtkBuilder *builder,
171 GObject *object,
172 const gchar *signal_name,
173 const gchar *handler_name,
174 GObject *connect_object,
175 GConnectFlags flags,
176 gpointer user_data)
177{
178 ReftestModule *module;
179 const char *directory;
180 GCallback func;
181 GClosure *closure;
182 char **split;
183
184 directory = user_data;
185 split = g_strsplit (handler_name, ":", -1);
186
187 switch (g_strv_length (split))
188 {
189 case 1:
190 func = ctk_builder_lookup_callback_symbol (builder, split[0]);
191
192 if (func)
193 {
194 module = NULL((void*)0);
195 }
196 else
197 {
198 module = reftest_module_new_self ();
199 if (module == NULL((void*)0))
200 {
201 g_error ("glib compiled without module support.");
202 return;
203 }
204 func = reftest_module_lookup (module, split[0]);
205 if (!func)
206 {
207 g_error ("failed to lookup handler for name '%s' when connecting signals", split[0]);
208 return;
209 }
210 }
211 break;
212 case 2:
213 if (g_getenv ("REFTEST_MODULE_DIR"))
214 directory = g_getenv ("REFTEST_MODULE_DIR");
215 module = reftest_module_new (directory, split[0]);
216 if (module == NULL((void*)0))
217 {
218 g_error ("Could not load module '%s' from '%s' when looking up '%s'", split[0], directory, handler_name);
219 return;
This statement is never executed
220 }
221 func = reftest_module_lookup (module, split[1]);
222 if (!func)
223 {
224 g_error ("failed to lookup handler for name '%s' in module '%s'", split[1], split[0]);
225 return;
226 }
227 break;
228 default:
229 g_error ("Could not connect signal handler named '%s'", handler_name);
230 return;
231 }
232
233 g_strfreev (split);
234
235 if (connect_object)
236 {
237 if (flags & G_CONNECT_SWAPPED)
238 closure = g_cclosure_new_object_swap (func, connect_object);
239 else
240 closure = g_cclosure_new_object (func, connect_object);
241 }
242 else
243 {
244 if (flags & G_CONNECT_SWAPPED)
245 closure = g_cclosure_new_swap (func, NULL((void*)0), NULL((void*)0));
246 else
247 closure = g_cclosure_new (func, NULL((void*)0), NULL((void*)0));
248 }
249
250 if (module)
251 g_closure_add_finalize_notifier (closure, module, (GClosureNotify) reftest_module_unref);
252
253 g_signal_connect_closure (object, signal_name, closure, flags & G_CONNECT_AFTER ? TRUE(!(0)) : FALSE(0));
254}
255
256cairo_surface_t *
257reftest_snapshot_ui_file (const char *ui_file)
258{
259 CtkWidget *window;
260 CtkBuilder *builder;
261 GError *error = NULL((void*)0);
262 char *directory;
263
264 directory = g_path_get_dirname (ui_file);
265
266 builder = ctk_builder_new ();
267 ctk_builder_add_from_file (builder, ui_file, &error);
268 g_assert_no_error (error)do { if (error) g_assertion_message_error (((gchar*) 0), "reftest-snapshot.c"
, 268, ((const char*) (__func__)), "error", error, 0, 0); } while
(0)
;
269 ctk_builder_connect_signals_full (builder, connect_signals, directory);
270 window = builder_get_toplevel (builder);
271 g_object_unref (builder);
272 g_free (directory);
273 g_assert (window)do { if (window) ; else g_assertion_message_expr (((gchar*) 0
), "reftest-snapshot.c", 273, ((const char*) (__func__)), "window"
); } while (0)
;
274
275 ctk_widget_show (window);
276
277 return snapshot_widget (window, SNAPSHOT_WINDOW);
278}