File: | tests/testlist4.c |
Warning: | line 130, column 49 Casting a non-structure type to a structure type and accessing a field can lead to memory access errors or data corruption |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | #include <ctk/ctk.h> |
2 | |
3 | typedef struct |
4 | { |
5 | CtkApplication parent_instance; |
6 | } TestApp; |
7 | |
8 | typedef CtkApplicationClass TestAppClass; |
9 | |
10 | G_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 | |
12 | static CtkWidget *create_row (const gchar *label); |
13 | |
14 | static void |
15 | activate_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 | |
25 | static void |
26 | activate_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 | |
36 | static void |
37 | activate_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 | |
50 | static void |
51 | row_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 | |
64 | static void |
65 | add_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 | |
73 | static CtkWidget * |
74 | create_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 | |
86 | static void |
87 | new_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")); |
Casting a non-structure type to a structure type and accessing a field can lead to memory access errors or data corruption | |
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")); |
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 | |
181 | static void |
182 | test_app_activate (GApplication *application) |
183 | { |
184 | new_window (application); |
185 | } |
186 | |
187 | static void |
188 | test_app_init (TestApp *app) |
189 | { |
190 | } |
191 | |
192 | static void |
193 | test_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 | |
198 | TestApp * |
199 | test_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 | |
213 | int |
214 | main (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 | } |