| File: | ctk/ctkcolorpickerportal.c |
| Warning: | line 210, column 37 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 | /* CTK - The GIMP Toolkit |
| 2 | * Copyright (C) 2018, Red Hat, Inc |
| 3 | * |
| 4 | * This library is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU Lesser General Public |
| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 2 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Lesser General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public |
| 15 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 16 | */ |
| 17 | |
| 18 | #include "config.h" |
| 19 | |
| 20 | #include "ctkcolorpickerportalprivate.h" |
| 21 | #include "ctkprivate.h" |
| 22 | #include <gio/gio.h> |
| 23 | |
| 24 | struct _CtkColorPickerPortal |
| 25 | { |
| 26 | GObject parent_instance; |
| 27 | |
| 28 | GDBusProxy *portal_proxy; |
| 29 | guint portal_signal_id; |
| 30 | GTask *task; |
| 31 | }; |
| 32 | |
| 33 | struct _CtkColorPickerPortalClass |
| 34 | { |
| 35 | GObjectClass parent_class; |
| 36 | }; |
| 37 | |
| 38 | static GInitableIface *initable_parent_iface; |
| 39 | static void ctk_color_picker_portal_initable_iface_init (GInitableIface *iface); |
| 40 | static void ctk_color_picker_portal_iface_init (CtkColorPickerInterface *iface); |
| 41 | |
| 42 | G_DEFINE_TYPE_WITH_CODE (CtkColorPickerPortal, ctk_color_picker_portal, G_TYPE_OBJECT,static void ctk_color_picker_portal_init (CtkColorPickerPortal *self); static void ctk_color_picker_portal_class_init (CtkColorPickerPortalClass *klass); static GType ctk_color_picker_portal_get_type_once ( void); static gpointer ctk_color_picker_portal_parent_class = ((void*)0); static gint CtkColorPickerPortal_private_offset; static void ctk_color_picker_portal_class_intern_init (gpointer klass) { ctk_color_picker_portal_parent_class = g_type_class_peek_parent (klass); if (CtkColorPickerPortal_private_offset != 0) g_type_class_adjust_private_offset (klass, &CtkColorPickerPortal_private_offset); ctk_color_picker_portal_class_init ((CtkColorPickerPortalClass*) klass); } __attribute__ ((__unused__ )) static inline gpointer ctk_color_picker_portal_get_instance_private (CtkColorPickerPortal *self) { return (((gpointer) ((guint8* ) (self) + (glong) (CtkColorPickerPortal_private_offset)))); } GType ctk_color_picker_portal_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 = ctk_color_picker_portal_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 ctk_color_picker_portal_get_type_once (void) { GType g_define_type_id = g_type_register_static_simple (((GType) ((20) << (2))), g_intern_static_string ("CtkColorPickerPortal" ), sizeof (CtkColorPickerPortalClass), (GClassInitFunc)(void ( *)(void)) ctk_color_picker_portal_class_intern_init, sizeof ( CtkColorPickerPortal), (GInstanceInitFunc)(void (*)(void)) ctk_color_picker_portal_init , (GTypeFlags) 0); { {{ const GInterfaceInfo g_implement_interface_info = { (GInterfaceInitFunc)(void (*)(void)) ctk_color_picker_portal_initable_iface_init , ((void*)0), ((void*)0) }; g_type_add_interface_static (g_define_type_id , (g_initable_get_type ()), &g_implement_interface_info); } { const GInterfaceInfo g_implement_interface_info = { (GInterfaceInitFunc )(void (*)(void)) ctk_color_picker_portal_iface_init, ((void* )0), ((void*)0) }; g_type_add_interface_static (g_define_type_id , (ctk_color_picker_get_type ()), &g_implement_interface_info ); };} } return g_define_type_id; } |
| 43 | G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, ctk_color_picker_portal_initable_iface_init)static void ctk_color_picker_portal_init (CtkColorPickerPortal *self); static void ctk_color_picker_portal_class_init (CtkColorPickerPortalClass *klass); static GType ctk_color_picker_portal_get_type_once ( void); static gpointer ctk_color_picker_portal_parent_class = ((void*)0); static gint CtkColorPickerPortal_private_offset; static void ctk_color_picker_portal_class_intern_init (gpointer klass) { ctk_color_picker_portal_parent_class = g_type_class_peek_parent (klass); if (CtkColorPickerPortal_private_offset != 0) g_type_class_adjust_private_offset (klass, &CtkColorPickerPortal_private_offset); ctk_color_picker_portal_class_init ((CtkColorPickerPortalClass*) klass); } __attribute__ ((__unused__ )) static inline gpointer ctk_color_picker_portal_get_instance_private (CtkColorPickerPortal *self) { return (((gpointer) ((guint8* ) (self) + (glong) (CtkColorPickerPortal_private_offset)))); } GType ctk_color_picker_portal_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 = ctk_color_picker_portal_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 ctk_color_picker_portal_get_type_once (void) { GType g_define_type_id = g_type_register_static_simple (((GType) ((20) << (2))), g_intern_static_string ("CtkColorPickerPortal" ), sizeof (CtkColorPickerPortalClass), (GClassInitFunc)(void ( *)(void)) ctk_color_picker_portal_class_intern_init, sizeof ( CtkColorPickerPortal), (GInstanceInitFunc)(void (*)(void)) ctk_color_picker_portal_init , (GTypeFlags) 0); { {{ const GInterfaceInfo g_implement_interface_info = { (GInterfaceInitFunc)(void (*)(void)) ctk_color_picker_portal_initable_iface_init , ((void*)0), ((void*)0) }; g_type_add_interface_static (g_define_type_id , (g_initable_get_type ()), &g_implement_interface_info); } { const GInterfaceInfo g_implement_interface_info = { (GInterfaceInitFunc )(void (*)(void)) ctk_color_picker_portal_iface_init, ((void* )0), ((void*)0) }; g_type_add_interface_static (g_define_type_id , (ctk_color_picker_get_type ()), &g_implement_interface_info ); };} } return g_define_type_id; } |
| 44 | G_IMPLEMENT_INTERFACE (CTK_TYPE_COLOR_PICKER, ctk_color_picker_portal_iface_init))static void ctk_color_picker_portal_init (CtkColorPickerPortal *self); static void ctk_color_picker_portal_class_init (CtkColorPickerPortalClass *klass); static GType ctk_color_picker_portal_get_type_once ( void); static gpointer ctk_color_picker_portal_parent_class = ((void*)0); static gint CtkColorPickerPortal_private_offset; static void ctk_color_picker_portal_class_intern_init (gpointer klass) { ctk_color_picker_portal_parent_class = g_type_class_peek_parent (klass); if (CtkColorPickerPortal_private_offset != 0) g_type_class_adjust_private_offset (klass, &CtkColorPickerPortal_private_offset); ctk_color_picker_portal_class_init ((CtkColorPickerPortalClass*) klass); } __attribute__ ((__unused__ )) static inline gpointer ctk_color_picker_portal_get_instance_private (CtkColorPickerPortal *self) { return (((gpointer) ((guint8* ) (self) + (glong) (CtkColorPickerPortal_private_offset)))); } GType ctk_color_picker_portal_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 = ctk_color_picker_portal_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 ctk_color_picker_portal_get_type_once (void) { GType g_define_type_id = g_type_register_static_simple (((GType) ((20) << (2))), g_intern_static_string ("CtkColorPickerPortal" ), sizeof (CtkColorPickerPortalClass), (GClassInitFunc)(void ( *)(void)) ctk_color_picker_portal_class_intern_init, sizeof ( CtkColorPickerPortal), (GInstanceInitFunc)(void (*)(void)) ctk_color_picker_portal_init , (GTypeFlags) 0); { {{ const GInterfaceInfo g_implement_interface_info = { (GInterfaceInitFunc)(void (*)(void)) ctk_color_picker_portal_initable_iface_init , ((void*)0), ((void*)0) }; g_type_add_interface_static (g_define_type_id , (g_initable_get_type ()), &g_implement_interface_info); } { const GInterfaceInfo g_implement_interface_info = { (GInterfaceInitFunc )(void (*)(void)) ctk_color_picker_portal_iface_init, ((void* )0), ((void*)0) }; g_type_add_interface_static (g_define_type_id , (ctk_color_picker_get_type ()), &g_implement_interface_info ); };} } return g_define_type_id; } |
| 45 | |
| 46 | static gboolean |
| 47 | ctk_color_picker_portal_initable_init (GInitable *initable, |
| 48 | GCancellable *cancellable G_GNUC_UNUSED__attribute__ ((__unused__)), |
| 49 | GError **error) |
| 50 | { |
| 51 | CtkColorPickerPortal *picker = CTK_COLOR_PICKER_PORTAL (initable); |
| 52 | char *owner; |
| 53 | GVariant *ret; |
| 54 | guint version = 0; |
| 55 | |
| 56 | if (!ctk_should_use_portal ()) |
| 57 | return FALSE(0); |
| 58 | |
| 59 | picker->portal_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, |
| 60 | G_DBUS_PROXY_FLAGS_NONE, |
| 61 | NULL((void*)0), |
| 62 | "org.freedesktop.portal.Desktop", |
| 63 | "/org/freedesktop/portal/desktop", |
| 64 | "org.freedesktop.portal.Screenshot", |
| 65 | NULL((void*)0), |
| 66 | error); |
| 67 | |
| 68 | if (picker->portal_proxy == NULL((void*)0)) |
| 69 | { |
| 70 | g_debug ("Failed to create screenshot portal proxy"); |
| 71 | return FALSE(0); |
| 72 | } |
| 73 | |
| 74 | owner = g_dbus_proxy_get_name_owner (picker->portal_proxy); |
| 75 | if (owner == NULL((void*)0)) |
| 76 | { |
| 77 | g_debug ("org.freedesktop.portal.Screenshot not provided"); |
| 78 | g_clear_object (&picker->portal_proxy)do { _Static_assert (sizeof *((&picker->portal_proxy)) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ (((&picker->portal_proxy))) _pp = ((&picker->portal_proxy )); __typeof__ (*((&picker->portal_proxy))) _ptr = *_pp ; *_pp = ((void*)0); if (_ptr) (g_object_unref) (_ptr); } while (0); |
| 79 | return FALSE(0); |
| 80 | } |
| 81 | g_free (owner); |
| 82 | |
| 83 | ret = g_dbus_proxy_get_cached_property (picker->portal_proxy, "version"); |
| 84 | if (ret) |
| 85 | { |
| 86 | version = g_variant_get_uint32 (ret); |
| 87 | g_variant_unref (ret); |
| 88 | } |
| 89 | |
| 90 | if (version != 2) |
| 91 | { |
| 92 | g_debug ("Screenshot portal version: %u", version); |
| 93 | g_clear_object (&picker->portal_proxy)do { _Static_assert (sizeof *((&picker->portal_proxy)) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ (((&picker->portal_proxy))) _pp = ((&picker->portal_proxy )); __typeof__ (*((&picker->portal_proxy))) _ptr = *_pp ; *_pp = ((void*)0); if (_ptr) (g_object_unref) (_ptr); } while (0); |
| 94 | return FALSE(0); |
| 95 | } |
| 96 | |
| 97 | return TRUE(!(0)); |
| 98 | } |
| 99 | |
| 100 | static void |
| 101 | ctk_color_picker_portal_initable_iface_init (GInitableIface *iface) |
| 102 | { |
| 103 | initable_parent_iface = g_type_interface_peek_parent (iface); |
| 104 | iface->init = ctk_color_picker_portal_initable_init; |
| 105 | } |
| 106 | |
| 107 | static void |
| 108 | ctk_color_picker_portal_init (CtkColorPickerPortal *picker G_GNUC_UNUSED__attribute__ ((__unused__))) |
| 109 | { |
| 110 | } |
| 111 | |
| 112 | static void |
| 113 | ctk_color_picker_portal_finalize (GObject *object) |
| 114 | { |
| 115 | CtkColorPickerPortal *picker = CTK_COLOR_PICKER_PORTAL (object); |
| 116 | |
| 117 | g_clear_object (&picker->portal_proxy)do { _Static_assert (sizeof *((&picker->portal_proxy)) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ (((&picker->portal_proxy))) _pp = ((&picker->portal_proxy )); __typeof__ (*((&picker->portal_proxy))) _ptr = *_pp ; *_pp = ((void*)0); if (_ptr) (g_object_unref) (_ptr); } while (0); |
| 118 | |
| 119 | G_OBJECT_CLASS (ctk_color_picker_portal_parent_class)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((ctk_color_picker_portal_parent_class)), (((GType) ((20) << (2))))))))->finalize (object); |
| 120 | } |
| 121 | |
| 122 | static void |
| 123 | ctk_color_picker_portal_class_init (CtkColorPickerPortalClass *class) |
| 124 | { |
| 125 | GObjectClass *object_class = G_OBJECT_CLASS (class)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((class)), (((GType) ((20) << (2)))))))); |
| 126 | |
| 127 | object_class->finalize = ctk_color_picker_portal_finalize; |
| 128 | } |
| 129 | |
| 130 | CtkColorPicker * |
| 131 | ctk_color_picker_portal_new (void) |
| 132 | { |
| 133 | return CTK_COLOR_PICKER (g_initable_new (CTK_TYPE_COLOR_PICKER_PORTAL, NULL, NULL, NULL))((((CtkColorPicker*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((g_initable_new (ctk_color_picker_portal_get_type (), ((void *)0), ((void*)0), ((void*)0)))), ((ctk_color_picker_get_type ( ))))))); |
| 134 | } |
| 135 | |
| 136 | static void |
| 137 | portal_response_received (GDBusConnection *connection, |
| 138 | const char *sender_name G_GNUC_UNUSED__attribute__ ((__unused__)), |
| 139 | const char *object_path G_GNUC_UNUSED__attribute__ ((__unused__)), |
| 140 | const char *interface_name G_GNUC_UNUSED__attribute__ ((__unused__)), |
| 141 | const char *signal_name G_GNUC_UNUSED__attribute__ ((__unused__)), |
| 142 | GVariant *parameters, |
| 143 | gpointer user_data) |
| 144 | { |
| 145 | CtkColorPickerPortal *picker = user_data; |
| 146 | guint32 response; |
| 147 | GVariant *ret; |
| 148 | |
| 149 | g_dbus_connection_signal_unsubscribe (connection, picker->portal_signal_id); |
| 150 | picker->portal_signal_id = 0; |
| 151 | |
| 152 | g_variant_get (parameters, "(u@a{sv})", &response, &ret); |
| 153 | |
| 154 | if (response == 0) |
| 155 | { |
| 156 | CdkRGBA c; |
| 157 | |
| 158 | c.alpha = 1.0; |
| 159 | if (g_variant_lookup (ret, "color", "(ddd)", &c.red, &c.green, &c.blue)) |
| 160 | g_task_return_pointer (picker->task, cdk_rgba_copy (&c), (GDestroyNotify)cdk_rgba_free); |
| 161 | else |
| 162 | g_task_return_new_error (picker->task, |
| 163 | G_IO_ERRORg_io_error_quark(), |
| 164 | G_IO_ERROR_FAILED, |
| 165 | "No color received"); |
| 166 | } |
| 167 | else |
| 168 | g_task_return_new_error (picker->task, |
| 169 | G_IO_ERRORg_io_error_quark(), |
| 170 | G_IO_ERROR_FAILED, |
| 171 | "PickColor error"); |
| 172 | |
| 173 | g_variant_unref (ret); |
| 174 | |
| 175 | g_clear_object (&picker->task)do { _Static_assert (sizeof *((&picker->task)) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ ((( &picker->task))) _pp = ((&picker->task)); __typeof__ (*((&picker->task))) _ptr = *_pp; *_pp = ((void*)0); if (_ptr) (g_object_unref) (_ptr); } while (0); |
| 176 | } |
| 177 | |
| 178 | static void |
| 179 | ctk_color_picker_portal_pick (CtkColorPicker *cp, |
| 180 | GAsyncReadyCallback callback, |
| 181 | gpointer user_data) |
| 182 | { |
| 183 | CtkColorPickerPortal *picker = CTK_COLOR_PICKER_PORTAL (cp); |
| 184 | GVariantBuilder options; |
| 185 | GDBusConnection *connection; |
| 186 | char *token; |
| 187 | char *handle; |
| 188 | |
| 189 | if (picker->task) |
| 190 | return; |
| 191 | |
| 192 | picker->task = g_task_new (picker, NULL((void*)0), callback, user_data); |
| 193 | |
| 194 | connection = g_dbus_proxy_get_connection (picker->portal_proxy); |
| 195 | |
| 196 | handle = ctk_get_portal_request_path (connection, &token); |
| 197 | picker->portal_signal_id = g_dbus_connection_signal_subscribe (connection, |
| 198 | "org.freedesktop.portal.Desktop", |
| 199 | "org.freedesktop.portal.Request", |
| 200 | "Response", |
| 201 | handle, |
| 202 | NULL((void*)0), |
| 203 | G_DBUS_SIGNAL_FLAGS_NO_MATCH_RULE, |
| 204 | portal_response_received, |
| 205 | picker, |
| 206 | NULL((void*)0)); |
| 207 | |
| 208 | g_free (handle); |
| 209 | |
| 210 | g_variant_builder_init (&options, G_VARIANT_TYPE_VARDICT((const GVariantType *) "a{sv}")); |
Casting a non-structure type to a structure type and accessing a field can lead to memory access errors or data corruption | |
| 211 | g_variant_builder_add (&options, "{sv}", "handle_token", g_variant_new_string (token)); |
| 212 | g_free (token); |
| 213 | |
| 214 | g_dbus_proxy_call (picker->portal_proxy, |
| 215 | "PickColor", |
| 216 | g_variant_new ("(sa{sv})", "", &options), |
| 217 | 0, |
| 218 | -1, |
| 219 | NULL((void*)0), |
| 220 | NULL((void*)0), |
| 221 | NULL((void*)0)); |
| 222 | } |
| 223 | |
| 224 | static CdkRGBA * |
| 225 | ctk_color_picker_portal_pick_finish (CtkColorPicker *cp, |
| 226 | GAsyncResult *res, |
| 227 | GError **error) |
| 228 | { |
| 229 | g_return_val_if_fail (g_task_is_valid (res, cp), NULL)do { if ((g_task_is_valid (res, cp))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "g_task_is_valid (res, cp)" ); return (((void*)0)); } } while (0); |
| 230 | |
| 231 | return g_task_propagate_pointer (G_TASK (res)((((GTask*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((res)), ((g_task_get_type ())))))), error); |
| 232 | } |
| 233 | |
| 234 | static void |
| 235 | ctk_color_picker_portal_iface_init (CtkColorPickerInterface *iface) |
| 236 | { |
| 237 | iface->pick = ctk_color_picker_portal_pick; |
| 238 | iface->pick_finish = ctk_color_picker_portal_pick_finish; |
| 239 | } |