Bug Summary

File:tests/testlist4.c
Warning:line 150, column 46
Casting a non-structure type to a structure type and accessing a field can lead to memory access errors or data corruption

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 testlist4.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 -fcoverage-compilation-dir=/rootdir/tests -resource-dir /usr/lib/llvm-16/lib/clang/16 -D HAVE_CONFIG_H -I . -I .. -I .. -I ../cdk -I ../cdk -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/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 -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/tests -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-172241-43638-1 -x c testlist4.c
1#include <ctk/ctk.h>
2
3typedef struct
4{
5 CtkApplication parent_instance;
6} TestApp;
7
8typedef CtkApplicationClass TestAppClass;
9
10G_DEFINE_TYPE (TestApp, test_app, CTK_TYPE_APPLICATION)static void test_app_init (TestApp *self); static void test_app_class_init
(TestAppClass *klass); static GType test_app_get_type_once (
void); static gpointer test_app_parent_class = ((void*)0); static
gint TestApp_private_offset; static void test_app_class_intern_init
(gpointer klass) { test_app_parent_class = g_type_class_peek_parent
(klass); if (TestApp_private_offset != 0) g_type_class_adjust_private_offset
(klass, &TestApp_private_offset); test_app_class_init ((
TestAppClass*) klass); } __attribute__ ((__unused__)) static inline
gpointer test_app_get_instance_private (TestApp *self) { return
(((gpointer) ((guint8*) (self) + (glong) (TestApp_private_offset
)))); } GType test_app_get_type (void) { static GType static_g_define_type_id
= 0; if ((__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id
) == sizeof (gpointer), "Expression evaluates to false"); (void
) (0 ? (gpointer) * (&static_g_define_type_id) : ((void*)
0)); (!(__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id
) == sizeof (gpointer), "Expression evaluates to false"); __typeof__
(*(&static_g_define_type_id)) gapg_temp_newval; __typeof__
((&static_g_define_type_id)) gapg_temp_atomic = (&static_g_define_type_id
); __atomic_load (gapg_temp_atomic, &gapg_temp_newval, 5)
; gapg_temp_newval; })) && g_once_init_enter_pointer (
&static_g_define_type_id)); })) ) { GType g_define_type_id
= test_app_get_type_once (); (__extension__ ({ _Static_assert
(sizeof *(&static_g_define_type_id) == sizeof (gpointer)
, "Expression evaluates to false"); 0 ? (void) (*(&static_g_define_type_id
) = (g_define_type_id)) : (void) 0; g_once_init_leave_pointer
((&static_g_define_type_id), (gpointer) (guintptr) (g_define_type_id
)); })) ; } return static_g_define_type_id; } __attribute__ (
(__noinline__)) static GType test_app_get_type_once (void) { GType
g_define_type_id = g_type_register_static_simple ((ctk_application_get_type
()), g_intern_static_string ("TestApp"), sizeof (TestAppClass
), (GClassInitFunc)(void (*)(void)) test_app_class_intern_init
, sizeof (TestApp), (GInstanceInitFunc)(void (*)(void)) test_app_init
, (GTypeFlags) 0); { {{};} } return g_define_type_id; }
11
12static CtkWidget *create_row (const gchar *label);
13
14static void
15activate_first_row (GSimpleAction *simple,
16 GVariant *parameter,
17 gpointer user_data)
18{
19 const gchar *text = "First row activated (no parameter action)";
20
21 g_print ("%s\n", text);
22 ctk_label_set_label (CTK_LABEL (user_data)((((CtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((user_data)), ((ctk_label_get_type ()))))))
, text);
23}
24
25static void
26activate_print_string (GSimpleAction *simple,
27 GVariant *parameter,
28 gpointer user_data)
29{
30 const gchar *text = g_variant_get_string (parameter, NULL((void*)0));
31
32 g_print ("%s\n", text);
33 ctk_label_set_label (CTK_LABEL (user_data)((((CtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((user_data)), ((ctk_label_get_type ()))))))
, text);
34}
35
36static void
37activate_print_int (GSimpleAction *simple,
38 GVariant *parameter,
39 gpointer user_data)
40{
41 const int value = g_variant_get_int32 (parameter);
42 gchar *text;
43
44 text = g_strdup_printf ("Row %d activated (int action)", value);
45
46 g_print ("%s\n", text);
47 ctk_label_set_label (CTK_LABEL (user_data)((((CtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((user_data)), ((ctk_label_get_type ()))))))
, text);
48}
49
50static void
51row_without_gaction_activated_cb (CtkListBox *list,
52 CtkListBoxRow *row,
53 gpointer user_data)
54{
55 int index = ctk_list_box_row_get_index (row);
56 gchar *text;
57
58 text = g_strdup_printf ("Row %d activated (signal based)", index);
59
60 g_print ("%s\n", text);
61 ctk_label_set_label (CTK_LABEL (user_data)((((CtkLabel*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((user_data)), ((ctk_label_get_type ()))))))
, text);
62}
63
64static void
65add_separator (CtkListBoxRow *row, CtkListBoxRow *before, gpointer data)
66{
67 if (!before)
68 return;
69
70 ctk_list_box_row_set_header (row, ctk_separator_new (CTK_ORIENTATION_HORIZONTAL));
71}
72
73static CtkWidget *
74create_row (const gchar *text)
75{
76 CtkWidget *row_content, *label;
77
78 row_content = ctk_box_new (CTK_ORIENTATION_HORIZONTAL, 10);
79
80 label = ctk_label_new (text);
81 ctk_container_add (CTK_CONTAINER (row_content)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((row_content)), ((ctk_container_get_type ()))))))
, label);
82
83 return row_content;
84}
85
86static void
87new_window (GApplication *app)
88{
89 CtkWidget *window, *grid, *sw, *list, *label;
90 GSimpleAction *action;
91
92 CtkWidget *row_content;
93 CtkListBoxRow *row;
94
95 gint i;
96 gchar *text;
97
98 window = ctk_application_window_new (CTK_APPLICATION (app)((((CtkApplication*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((app)), ((ctk_application_get_type ()))))))
);
99 ctk_window_set_default_size (CTK_WINDOW (window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_window_get_type ()))))))
, 300, 300);
100
101 /* widget creation */
102 grid = ctk_grid_new ();
103 ctk_container_add (CTK_CONTAINER (window)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_container_get_type ()))))))
, grid);
104 sw = ctk_scrolled_window_new (NULL((void*)0), NULL((void*)0));
105 ctk_widget_set_hexpand (CTK_WIDGET (sw)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((sw)), ((ctk_widget_get_type ()))))))
, 1);
106 ctk_widget_set_vexpand (CTK_WIDGET (sw)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((sw)), ((ctk_widget_get_type ()))))))
, 1);
107 ctk_grid_attach (CTK_GRID (grid)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((grid)), ((ctk_grid_get_type ()))))))
, sw, 0, 0, 1, 1);
108
109 list = ctk_list_box_new ();
110 ctk_list_box_set_selection_mode (CTK_LIST_BOX (list)((((CtkListBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((list)), ((ctk_list_box_get_type ()))))))
, CTK_SELECTION_NONE);
111 ctk_list_box_set_header_func (CTK_LIST_BOX (list)((((CtkListBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((list)), ((ctk_list_box_get_type ()))))))
, add_separator, NULL((void*)0), NULL((void*)0));
112 ctk_container_add (CTK_CONTAINER (sw)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((sw)), ((ctk_container_get_type ()))))))
, list);
113
114 label = ctk_label_new ("No row activated");
115 ctk_grid_attach (CTK_GRID (grid)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((grid)), ((ctk_grid_get_type ()))))))
, label, 0, 1, 1, 1);
116
117 /* no parameter action row */
118 action = g_simple_action_new ("first-row-action", NULL((void*)0));
119 g_action_map_add_action (G_ACTION_MAP (window)((((GActionMap*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((g_action_map_get_type ()))))))
, G_ACTION (action)((((GAction*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((action)), ((g_action_get_type ()))))))
);
120
121 row_content = create_row ("First row (no parameter action)");
122 ctk_list_box_insert (CTK_LIST_BOX (list)((((CtkListBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((list)), ((ctk_list_box_get_type ()))))))
, row_content, -1);
123
124 row = ctk_list_box_get_row_at_index (CTK_LIST_BOX (list)((((CtkListBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((list)), ((ctk_list_box_get_type ()))))))
, 0);
125 ctk_actionable_set_action_name (CTK_ACTIONABLE (row)((((CtkActionable*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((row)), ((ctk_actionable_get_type ()))))))
, "win.first-row-action");
126
127 g_signal_connect (action, "activate", (GCallback) activate_first_row, label)g_signal_connect_data ((action), ("activate"), ((GCallback) activate_first_row
), (label), ((void*)0), (GConnectFlags) 0)
;
128
129 /* string action rows */
130 action = g_simple_action_new ("print-string", G_VARIANT_TYPE_STRING((const GVariantType *) "s"));
131 g_action_map_add_action (G_ACTION_MAP (window)((((GActionMap*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((g_action_map_get_type ()))))))
, G_ACTION (action)((((GAction*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((action)), ((g_action_get_type ()))))))
);
132
133 for (i = 1; i < 3; i++)
134 {
135 gchar *text2;
136
137 text = g_strdup_printf ("Row %d (string action)", i);
138 row_content = create_row (text);
139 ctk_list_box_insert (CTK_LIST_BOX (list)((((CtkListBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((list)), ((ctk_list_box_get_type ()))))))
, row_content, -1);
140
141 row = ctk_list_box_get_row_at_index (CTK_LIST_BOX (list)((((CtkListBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((list)), ((ctk_list_box_get_type ()))))))
, i);
142 text2 = g_strdup_printf ("Row %d activated (string action)", i);
143 ctk_actionable_set_action_target (CTK_ACTIONABLE (row)((((CtkActionable*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((row)), ((ctk_actionable_get_type ()))))))
, "s", text2);
144 ctk_actionable_set_action_name (CTK_ACTIONABLE (row)((((CtkActionable*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((row)), ((ctk_actionable_get_type ()))))))
, "win.print-string");
145 }
146
147 g_signal_connect (action, "activate", (GCallback) activate_print_string, label)g_signal_connect_data ((action), ("activate"), ((GCallback) activate_print_string
), (label), ((void*)0), (GConnectFlags) 0)
;
148
149 /* int action rows */
150 action = g_simple_action_new ("print-int", G_VARIANT_TYPE_INT32((const GVariantType *) "i"));
Casting a non-structure type to a structure type and accessing a field can lead to memory access errors or data corruption
151 g_action_map_add_action (G_ACTION_MAP (window)((((GActionMap*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((g_action_map_get_type ()))))))
, G_ACTION (action)((((GAction*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((action)), ((g_action_get_type ()))))))
);
152
153 for (i = 3; i < 5; i++)
154 {
155 text = g_strdup_printf ("Row %d (int action)", i);
156 row_content = create_row (text);
157 ctk_list_box_insert (CTK_LIST_BOX (list)((((CtkListBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((list)), ((ctk_list_box_get_type ()))))))
, row_content, -1);
158
159 row = ctk_list_box_get_row_at_index (CTK_LIST_BOX (list)((((CtkListBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((list)), ((ctk_list_box_get_type ()))))))
, i);
160 ctk_actionable_set_action_target (CTK_ACTIONABLE (row)((((CtkActionable*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((row)), ((ctk_actionable_get_type ()))))))
, "i", i);
161 ctk_actionable_set_action_name (CTK_ACTIONABLE (row)((((CtkActionable*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((row)), ((ctk_actionable_get_type ()))))))
, "win.print-int");
162 }
163
164 g_signal_connect (action, "activate", (GCallback) activate_print_int, label)g_signal_connect_data ((action), ("activate"), ((GCallback) activate_print_int
), (label), ((void*)0), (GConnectFlags) 0)
;
165
166 /* signal based row */
167 for (i = 5; i < 7; i++)
168 {
169 text = g_strdup_printf ("Row %d (signal based)", i);
170 row_content = create_row (text);
171 ctk_list_box_insert (CTK_LIST_BOX (list)((((CtkListBox*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((list)), ((ctk_list_box_get_type ()))))))
, row_content, -1);
172 }
173
174 g_signal_connect (list, "row-activated",g_signal_connect_data ((list), ("row-activated"), (((GCallback
) (row_without_gaction_activated_cb))), (label), ((void*)0), (
GConnectFlags) 0)
175 G_CALLBACK (row_without_gaction_activated_cb), label)g_signal_connect_data ((list), ("row-activated"), (((GCallback
) (row_without_gaction_activated_cb))), (label), ((void*)0), (
GConnectFlags) 0)
;
176
177 /* let the show begin */
178 ctk_widget_show_all (CTK_WIDGET (window)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_widget_get_type ()))))))
);
179}
180
181static void
182test_app_activate (GApplication *application)
183{
184 new_window (application);
185}
186
187static void
188test_app_init (TestApp *app)
189{
190}
191
192static void
193test_app_class_init (TestAppClass *class)
194{
195 G_APPLICATION_CLASS (class)((((GApplicationClass*) (void *) g_type_check_class_cast ((GTypeClass
*) ((class)), ((g_application_get_type ()))))))
->activate = test_app_activate;
196}
197
198TestApp *
199test_app_new (void)
200{
201 TestApp *test_app;
202
203 g_set_application_name ("Test List 4");
204
205 test_app = g_object_new (test_app_get_type (),
206 "application-id", "org.ctk.testlist4",
207 "flags", G_APPLICATION_DEFAULT_FLAGS,
208 NULL((void*)0));
209
210 return test_app;
211}
212
213int
214main (int argc, char **argv)
215{
216 TestApp *test_app;
217 int status;
218
219 test_app = test_app_new ();
220 status = g_application_run (G_APPLICATION (test_app)((((GApplication*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((test_app)), ((g_application_get_type ()))))))
, argc, argv);
221
222 g_object_unref (test_app);
223 return status;
224}