Bug Summary

File:tests/testlist4.c
Warning:line 132, column 49
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 -fdebug-compilation-dir=/rootdir/tests -fcoverage-compilation-dir=/rootdir/tests -resource-dir /usr/lib/llvm-19/lib/clang/19 -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-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-22-125755-43635-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 G_GNUC_UNUSED__attribute__ ((__unused__)),
16 GVariant *parameter G_GNUC_UNUSED__attribute__ ((__unused__)),
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 G_GNUC_UNUSED__attribute__ ((__unused__)),
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 G_GNUC_UNUSED__attribute__ ((__unused__)),
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 G_GNUC_UNUSED__attribute__ ((__unused__)),
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,
66 CtkListBoxRow *before,
67 gpointer data G_GNUC_UNUSED__attribute__ ((__unused__)))
68{
69 if (!before)
70 return;
71
72 ctk_list_box_row_set_header (row, ctk_separator_new (CTK_ORIENTATION_HORIZONTAL));
73}
74
75static CtkWidget *
76create_row (const gchar *text)
77{
78 CtkWidget *row_content, *label;
79
80 row_content = ctk_box_new (CTK_ORIENTATION_HORIZONTAL, 10);
81
82 label = ctk_label_new (text);
83 ctk_container_add (CTK_CONTAINER (row_content)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((row_content)), ((ctk_container_get_type ()))))))
, label);
84
85 return row_content;
86}
87
88static void
89new_window (GApplication *app)
90{
91 CtkWidget *window, *grid, *sw, *list, *label;
92 GSimpleAction *action;
93
94 CtkWidget *row_content;
95 CtkListBoxRow *row;
96
97 gint i;
98 gchar *text;
99
100 window = ctk_application_window_new (CTK_APPLICATION (app)((((CtkApplication*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((app)), ((ctk_application_get_type ()))))))
);
101 ctk_window_set_default_size (CTK_WINDOW (window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_window_get_type ()))))))
, 300, 300);
102
103 /* widget creation */
104 grid = ctk_grid_new ();
105 ctk_container_add (CTK_CONTAINER (window)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_container_get_type ()))))))
, grid);
106 sw = ctk_scrolled_window_new (NULL((void*)0), NULL((void*)0));
107 ctk_widget_set_hexpand (CTK_WIDGET (sw)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((sw)), ((ctk_widget_get_type ()))))))
, 1);
108 ctk_widget_set_vexpand (CTK_WIDGET (sw)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((sw)), ((ctk_widget_get_type ()))))))
, 1);
109 ctk_grid_attach (CTK_GRID (grid)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((grid)), ((ctk_grid_get_type ()))))))
, sw, 0, 0, 1, 1);
110
111 list = ctk_list_box_new ();
112 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);
113 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));
114 ctk_container_add (CTK_CONTAINER (sw)((((CtkContainer*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((sw)), ((ctk_container_get_type ()))))))
, list);
115
116 label = ctk_label_new ("No row activated");
117 ctk_grid_attach (CTK_GRID (grid)((((CtkGrid*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((grid)), ((ctk_grid_get_type ()))))))
, label, 0, 1, 1, 1);
118
119 /* no parameter action row */
120 action = g_simple_action_new ("first-row-action", NULL((void*)0));
121 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 ()))))))
);
122
123 row_content = create_row ("First row (no parameter action)");
124 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);
125
126 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);
127 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");
128
129 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)
;
130
131 /* string action rows */
132 action = g_simple_action_new ("print-string", G_VARIANT_TYPE_STRING((const GVariantType *) "s"));
Casting a non-structure type to a structure type and accessing a field can lead to memory access errors or data corruption
133 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 ()))))))
);
134
135 for (i = 1; i < 3; i++)
136 {
137 gchar *text2;
138
139 text = g_strdup_printf ("Row %d (string action)", i);
140 row_content = create_row (text);
141 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);
142
143 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);
144 text2 = g_strdup_printf ("Row %d activated (string action)", i);
145 ctk_actionable_set_action_target (CTK_ACTIONABLE (row)((((CtkActionable*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((row)), ((ctk_actionable_get_type ()))))))
, "s", text2);
146 ctk_actionable_set_action_name (CTK_ACTIONABLE (row)((((CtkActionable*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((row)), ((ctk_actionable_get_type ()))))))
, "win.print-string");
147 }
148
149 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)
;
150
151 /* int action rows */
152 action = g_simple_action_new ("print-int", G_VARIANT_TYPE_INT32((const GVariantType *) "i"));
153 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 ()))))))
);
154
155 for (i = 3; i < 5; i++)
156 {
157 text = g_strdup_printf ("Row %d (int action)", i);
158 row_content = create_row (text);
159 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);
160
161 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);
162 ctk_actionable_set_action_target (CTK_ACTIONABLE (row)((((CtkActionable*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((row)), ((ctk_actionable_get_type ()))))))
, "i", i);
163 ctk_actionable_set_action_name (CTK_ACTIONABLE (row)((((CtkActionable*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((row)), ((ctk_actionable_get_type ()))))))
, "win.print-int");
164 }
165
166 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)
;
167
168 /* signal based row */
169 for (i = 5; i < 7; i++)
170 {
171 text = g_strdup_printf ("Row %d (signal based)", i);
172 row_content = create_row (text);
173 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);
174 }
175
176 g_signal_connect (list, "row-activated",g_signal_connect_data ((list), ("row-activated"), (((GCallback
) (row_without_gaction_activated_cb))), (label), ((void*)0), (
GConnectFlags) 0)
177 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)
;
178
179 /* let the show begin */
180 ctk_widget_show_all (CTK_WIDGET (window)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_widget_get_type ()))))))
);
181}
182
183static void
184test_app_activate (GApplication *application)
185{
186 new_window (application);
187}
188
189static void
190test_app_init (TestApp *app G_GNUC_UNUSED__attribute__ ((__unused__)))
191{
192}
193
194static void
195test_app_class_init (TestAppClass *class)
196{
197 G_APPLICATION_CLASS (class)((((GApplicationClass*) (void *) g_type_check_class_cast ((GTypeClass
*) ((class)), ((g_application_get_type ()))))))
->activate = test_app_activate;
198}
199
200TestApp *
201test_app_new (void)
202{
203 TestApp *test_app;
204
205 g_set_application_name ("Test List 4");
206
207 test_app = g_object_new (test_app_get_type (),
208 "application-id", "org.ctk.testlist4",
209 "flags", G_APPLICATION_DEFAULT_FLAGS,
210 NULL((void*)0));
211
212 return test_app;
213}
214
215int
216main (int argc, char **argv)
217{
218 TestApp *test_app;
219 int status;
220
221 test_app = test_app_new ();
222 status = g_application_run (G_APPLICATION (test_app)((((GApplication*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((test_app)), ((g_application_get_type ()))))))
, argc, argv);
223
224 g_object_unref (test_app);
225 return status;
226}