Bug Summary

File:testsuite/reftests/reftest-snapshot.c
Warning:line 201, column 15
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 -fcoverage-compilation-dir=/rootdir/testsuite/reftests -resource-dir /usr/lib/llvm-16/lib/clang/16 -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-16/lib/clang/16/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 -fdebug-compilation-dir=/rootdir/testsuite/reftests -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-09-19-170505-43637-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, gpointer data)
86{
87 if (event->type == CDK_EXPOSE)
88 {
89 reftest_uninhibit_snapshot ();
90 cdk_event_handler_set ((CdkEventFunc) ctk_main_do_event, NULL((void*)0), NULL((void*)0));
91 }
92
93 ctk_main_do_event (event);
94}
95
96static cairo_surface_t *
97snapshot_widget (CtkWidget *widget, SnapshotMode mode)
98{
99 cairo_surface_t *surface;
100 cairo_pattern_t *bg;
101 cairo_t *cr;
102
103 g_assert (ctk_widget_get_realized (widget))do { if (ctk_widget_get_realized (widget)) ; else g_assertion_message_expr
(((gchar*) 0), "reftest-snapshot.c", 103, ((const char*) (__func__
)), "ctk_widget_get_realized (widget)"); } while (0)
;
104
105 loop = g_main_loop_new (NULL((void*)0), FALSE(0));
106
107 /* We wait until the widget is drawn for the first time.
108 * We can not wait for a CtkWidget::draw event, because that might not
109 * happen if the window is fully obscured by windowed child widgets.
110 * Alternatively, we could wait for an expose event on widget's window.
111 * Both of these are rather hairy, not sure what's best.
112 *
113 * We also use an inhibit mechanism, to give module functions a chance
114 * to delay the snapshot.
115 */
116 reftest_inhibit_snapshot ();
117 cdk_event_handler_set (check_for_draw, NULL((void*)0), NULL((void*)0));
118 g_main_loop_run (loop);
119
120 surface = cdk_window_create_similar_surface (ctk_widget_get_window (widget),
121 CAIRO_CONTENT_COLOR,
122 ctk_widget_get_allocated_width (widget),
123 ctk_widget_get_allocated_height (widget));
124
125 cr = cairo_create (surface);
126
127 switch (mode)
128 {
129 case SNAPSHOT_WINDOW:
130 {
131 CdkWindow *window = ctk_widget_get_window (widget);
132 if (cdk_window_get_window_type (window) == CDK_WINDOW_TOPLEVEL ||
133 cdk_window_get_window_type (window) == CDK_WINDOW_FOREIGN)
134 {
135 /* give the WM/server some time to sync. They need it.
136 * Also, do use popups instead of toplevels in your tests
137 * whenever you can.
138 */
139 cdk_display_sync (cdk_window_get_display (window));
140 g_timeout_add (500, quit_when_idle, loop);
141 g_main_loop_run (loop);
142 }
143 cdk_cairo_set_source_window (cr, window, 0, 0);
144 cairo_paint (cr);
145 }
146 break;
147 case SNAPSHOT_DRAW:
148 bg = cdk_window_get_background_pattern (ctk_widget_get_window (widget));
149 if (bg)
150 {
151 cairo_set_source (cr, bg);
152 cairo_paint (cr);
153 }
154 ctk_widget_draw (widget, cr);
155 break;
156 default:
157 g_assert_not_reached()do { g_assertion_message_expr (((gchar*) 0), "reftest-snapshot.c"
, 157, ((const char*) (__func__)), ((void*)0)); } while (0)
;
158 break;
159 }
160
161 cairo_destroy (cr);
162 g_main_loop_unref (loop);
163 ctk_widget_destroy (widget);
164
165 return surface;
166}
167
168static void
169connect_signals (CtkBuilder *builder,
170 GObject *object,
171 const gchar *signal_name,
172 const gchar *handler_name,
173 GObject *connect_object,
174 GConnectFlags flags,
175 gpointer user_data)
176{
177 ReftestModule *module;
178 const char *directory;
179 GCallback func;
180 GClosure *closure;
181 char **split;
182
183 directory = user_data;
184 split = g_strsplit (handler_name, ":", -1);
185
186 switch (g_strv_length (split))
187 {
188 case 1:
189 func = ctk_builder_lookup_callback_symbol (builder, split[0]);
190
191 if (func)
192 {
193 module = NULL((void*)0);
194 }
195 else
196 {
197 module = reftest_module_new_self ();
198 if (module == NULL((void*)0))
199 {
200 g_error ("glib compiled without module support.");
201 return;
This statement is never executed
202 }
203 func = reftest_module_lookup (module, split[0]);
204 if (!func)
205 {
206 g_error ("failed to lookup handler for name '%s' when connecting signals", split[0]);
207 return;
208 }
209 }
210 break;
211 case 2:
212 if (g_getenv ("REFTEST_MODULE_DIR"))
213 directory = g_getenv ("REFTEST_MODULE_DIR");
214 module = reftest_module_new (directory, split[0]);
215 if (module == NULL((void*)0))
216 {
217 g_error ("Could not load module '%s' from '%s' when looking up '%s'", split[0], directory, handler_name);
218 return;
219 }
220 func = reftest_module_lookup (module, split[1]);
221 if (!func)
222 {
223 g_error ("failed to lookup handler for name '%s' in module '%s'", split[1], split[0]);
224 return;
225 }
226 break;
227 default:
228 g_error ("Could not connect signal handler named '%s'", handler_name);
229 return;
230 }
231
232 g_strfreev (split);
233
234 if (connect_object)
235 {
236 if (flags & G_CONNECT_SWAPPED)
237 closure = g_cclosure_new_object_swap (func, connect_object);
238 else
239 closure = g_cclosure_new_object (func, connect_object);
240 }
241 else
242 {
243 if (flags & G_CONNECT_SWAPPED)
244 closure = g_cclosure_new_swap (func, NULL((void*)0), NULL((void*)0));
245 else
246 closure = g_cclosure_new (func, NULL((void*)0), NULL((void*)0));
247 }
248
249 if (module)
250 g_closure_add_finalize_notifier (closure, module, (GClosureNotify) reftest_module_unref);
251
252 g_signal_connect_closure (object, signal_name, closure, flags & G_CONNECT_AFTER ? TRUE(!(0)) : FALSE(0));
253}
254
255cairo_surface_t *
256reftest_snapshot_ui_file (const char *ui_file)
257{
258 CtkWidget *window;
259 CtkBuilder *builder;
260 GError *error = NULL((void*)0);
261 char *directory;
262
263 directory = g_path_get_dirname (ui_file);
264
265 builder = ctk_builder_new ();
266 ctk_builder_add_from_file (builder, ui_file, &error);
267 g_assert_no_error (error)do { if (error) g_assertion_message_error (((gchar*) 0), "reftest-snapshot.c"
, 267, ((const char*) (__func__)), "error", error, 0, 0); } while
(0)
;
268 ctk_builder_connect_signals_full (builder, connect_signals, directory);
269 window = builder_get_toplevel (builder);
270 g_object_unref (builder);
271 g_free (directory);
272 g_assert (window)do { if (window) ; else g_assertion_message_expr (((gchar*) 0
), "reftest-snapshot.c", 272, ((const char*) (__func__)), "window"
); } while (0)
;
273
274 ctk_widget_show (window);
275
276 return snapshot_widget (window, SNAPSHOT_WINDOW);
277}