File: | tests/testlist4.c |
Warning: | line 152, column 46 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 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 | |
25 | static void |
26 | activate_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 | |
36 | static void |
37 | activate_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 | |
50 | static void |
51 | row_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 | |
64 | static void |
65 | add_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 | |
75 | static CtkWidget * |
76 | create_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 | |
88 | static void |
89 | new_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")); |
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")); |
Casting a non-structure type to a structure type and accessing a field can lead to memory access errors or data corruption | |
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 | |
183 | static void |
184 | test_app_activate (GApplication *application) |
185 | { |
186 | new_window (application); |
187 | } |
188 | |
189 | static void |
190 | test_app_init (TestApp *app G_GNUC_UNUSED__attribute__ ((__unused__))) |
191 | { |
192 | } |
193 | |
194 | static void |
195 | test_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 | |
200 | TestApp * |
201 | test_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 | |
215 | int |
216 | main (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 | } |