diff options
author | Ignacio Casal Quinteiro <icq@gnome.org> | 2014-12-24 11:29:02 +0100 |
---|---|---|
committer | Ignacio Casal Quinteiro <icq@gnome.org> | 2014-12-24 11:40:04 +0100 |
commit | 3c0b242ec8f4e78db0797438e32540d4032f4f07 (patch) | |
tree | 171d5af928f8804ae0a0e8ad9fd2011a639f155d | |
parent | 310642b83b5fed300a9e7c560e92e4d320f3ce76 (diff) | |
download | gusb-3c0b242ec8f4e78db0797438e32540d4032f4f07.tar.gz |
Add guards for public methods
-rw-r--r-- | gusb/gusb-context.c | 22 | ||||
-rw-r--r-- | gusb/gusb-device-list.c | 8 | ||||
-rw-r--r-- | gusb/gusb-device.c | 50 |
3 files changed, 67 insertions, 13 deletions
diff --git a/gusb/gusb-context.c b/gusb/gusb-context.c index 1db3f31..d2d1288 100644 --- a/gusb/gusb-context.c +++ b/gusb/gusb-context.c @@ -633,7 +633,11 @@ void g_usb_context_set_debug (GUsbContext *context, GLogLevelFlags flags) { - GUsbContextPrivate *priv = context->priv; + GUsbContextPrivate *priv; + + g_return_if_fail (G_USB_IS_CONTEXT (context)); + + priv = context->priv; if (flags & (G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_INFO)) priv->debug_level = 3; @@ -666,10 +670,14 @@ g_usb_context_find_by_bus_address (GUsbContext *context, guint8 address, GError **error) { - GUsbContextPrivate *priv = context->priv; + GUsbContextPrivate *priv; GUsbDevice *device = NULL; guint i; + g_return_val_if_fail (G_USB_IS_CONTEXT (context), NULL); + + priv = context->priv; + g_usb_context_enumerate (context); for (i = 0; i < priv->devices->len; i++) { GUsbDevice *curr = g_ptr_array_index (priv->devices, i); @@ -679,6 +687,7 @@ g_usb_context_find_by_bus_address (GUsbContext *context, goto out; } } + g_set_error (error, G_USB_DEVICE_ERROR, G_USB_DEVICE_ERROR_NO_DEVICE, @@ -707,10 +716,14 @@ g_usb_context_find_by_vid_pid (GUsbContext *context, guint16 pid, GError **error) { - GUsbContextPrivate *priv = context->priv; + GUsbContextPrivate *priv; GUsbDevice *device = NULL; guint i; + g_return_val_if_fail (G_USB_IS_CONTEXT (context), NULL); + + priv = context->priv; + g_usb_context_enumerate (context); for (i = 0; i < priv->devices->len; i++) { GUsbDevice *curr = g_ptr_array_index (priv->devices, i); @@ -720,6 +733,7 @@ g_usb_context_find_by_vid_pid (GUsbContext *context, goto out; } } + g_set_error (error, G_USB_DEVICE_ERROR, G_USB_DEVICE_ERROR_NO_DEVICE, @@ -741,7 +755,9 @@ GPtrArray * g_usb_context_get_devices (GUsbContext *context) { g_return_val_if_fail (G_USB_IS_CONTEXT (context), NULL); + g_usb_context_enumerate (context); + return g_ptr_array_ref (context->priv->devices); } diff --git a/gusb/gusb-device-list.c b/gusb/gusb-device-list.c index b856134..dfe116a 100644 --- a/gusb/gusb-device-list.c +++ b/gusb/gusb-device-list.c @@ -206,6 +206,8 @@ g_usb_device_list_init (GUsbDeviceList *list) GPtrArray * g_usb_device_list_get_devices (GUsbDeviceList *list) { + g_return_val_if_fail (G_USB_IS_DEVICE_LIST (list), NULL); + return g_usb_context_get_devices (list->priv->context); } @@ -242,6 +244,9 @@ g_usb_device_list_find_by_bus_address (GUsbDeviceList *list, guint8 address, GError **error) { + g_return_val_if_fail (G_USB_IS_DEVICE_LIST (list), NULL); + g_return_val_if_fail (error == NULL || *error == NULL, NULL); + return g_usb_context_find_by_bus_address (list->priv->context, bus, address, error); } @@ -265,6 +270,9 @@ g_usb_device_list_find_by_vid_pid (GUsbDeviceList *list, guint16 pid, GError **error) { + g_return_val_if_fail (G_USB_IS_DEVICE_LIST (list), NULL); + g_return_val_if_fail (error == NULL || *error == NULL, NULL); + return g_usb_context_find_by_vid_pid (list->priv->context, vid, pid, error); } diff --git a/gusb/gusb-device.c b/gusb/gusb-device.c index edd5208..975bf6b 100644 --- a/gusb/gusb-device.c +++ b/gusb/gusb-device.c @@ -379,6 +379,7 @@ g_usb_device_open (GUsbDevice *device, gint rc; g_return_val_if_fail (G_USB_IS_DEVICE (device), FALSE); + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); if (device->priv->handle != NULL) { g_set_error (error, @@ -409,6 +410,7 @@ g_usb_device_close (GUsbDevice *device, GError **error) { g_return_val_if_fail (G_USB_IS_DEVICE (device), FALSE); + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); if (device->priv->handle == NULL) return g_usb_device_not_open_error (device, error); @@ -439,6 +441,7 @@ g_usb_device_reset (GUsbDevice *device, { gint rc; g_return_val_if_fail (G_USB_IS_DEVICE (device), FALSE); + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); if (device->priv->handle == NULL) return g_usb_device_not_open_error (device, error); @@ -468,6 +471,7 @@ g_usb_device_get_configuration (GUsbDevice *device, int config; g_return_val_if_fail (G_USB_IS_DEVICE (device), -1); + g_return_val_if_fail (error == NULL || *error == NULL, -1); if (device->priv->handle == NULL) { g_usb_device_not_open_error (device, error); @@ -506,6 +510,7 @@ g_usb_device_set_configuration (GUsbDevice *device, gint config_tmp = 0; g_return_val_if_fail (G_USB_IS_DEVICE (device), FALSE); + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); if (device->priv->handle == NULL) return g_usb_device_not_open_error (device, error); @@ -548,6 +553,7 @@ g_usb_device_claim_interface (GUsbDevice *device, gint rc; g_return_val_if_fail (G_USB_IS_DEVICE (device), FALSE); + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); if (device->priv->handle == NULL) return g_usb_device_not_open_error (device, error); @@ -589,6 +595,7 @@ g_usb_device_release_interface (GUsbDevice *device, gint rc; g_return_val_if_fail (G_USB_IS_DEVICE (device), FALSE); + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); if (device->priv->handle == NULL) return g_usb_device_not_open_error (device, error); @@ -632,7 +639,8 @@ g_usb_device_get_string_descriptor (GUsbDevice *device, /* libusb_get_string_descriptor_ascii returns max 128 bytes */ unsigned char buf[128]; - g_return_val_if_fail (G_USB_IS_DEVICE (device), FALSE); + g_return_val_if_fail (G_USB_IS_DEVICE (device), NULL); + g_return_val_if_fail (error == NULL || *error == NULL, NULL); if (device->priv->handle == NULL) { g_usb_device_not_open_error (device, error); @@ -984,9 +992,9 @@ g_usb_device_control_transfer_finish (GUsbDevice *device, { GSimpleAsyncResult *simple; - g_return_val_if_fail (G_IS_OBJECT (device), FALSE); - g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), FALSE); - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + g_return_val_if_fail (G_USB_IS_DEVICE (device), -1); + g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), -1); + g_return_val_if_fail (error == NULL || *error == NULL, -1); simple = G_SIMPLE_ASYNC_RESULT (res); if (g_simple_async_result_propagate_error (simple, error)) @@ -1141,9 +1149,9 @@ g_usb_device_bulk_transfer_finish (GUsbDevice *device, { GSimpleAsyncResult *simple; - g_return_val_if_fail (G_IS_OBJECT (device), FALSE); - g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), FALSE); - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + g_return_val_if_fail (G_USB_IS_DEVICE (device), -1); + g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), -1); + g_return_val_if_fail (error == NULL || *error == NULL, -1); simple = G_SIMPLE_ASYNC_RESULT (res); if (g_simple_async_result_propagate_error (simple, error)) @@ -1255,9 +1263,9 @@ g_usb_device_interrupt_transfer_finish (GUsbDevice *device, { GSimpleAsyncResult *simple; - g_return_val_if_fail (G_IS_OBJECT (device), FALSE); - g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), FALSE); - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + g_return_val_if_fail (G_USB_IS_DEVICE (device), -1); + g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), -1); + g_return_val_if_fail (error == NULL || *error == NULL, -1); simple = G_SIMPLE_ASYNC_RESULT (res); if (g_simple_async_result_propagate_error (simple, error)) @@ -1367,6 +1375,8 @@ g_usb_device_interrupt_transfer_async (GUsbDevice *device, const gchar * g_usb_device_get_platform_id (GUsbDevice *device) { + g_return_val_if_fail (G_USB_IS_DEVICE (device), NULL); + return device->priv->platform_id; } @@ -1383,6 +1393,8 @@ g_usb_device_get_platform_id (GUsbDevice *device) guint8 g_usb_device_get_bus (GUsbDevice *device) { + g_return_val_if_fail (G_USB_IS_DEVICE (device), 0); + return libusb_get_bus_number (device->priv->device); } @@ -1399,6 +1411,8 @@ g_usb_device_get_bus (GUsbDevice *device) guint8 g_usb_device_get_address (GUsbDevice *device) { + g_return_val_if_fail (G_USB_IS_DEVICE (device), 0); + return libusb_get_device_address (device->priv->device); } @@ -1415,6 +1429,8 @@ g_usb_device_get_address (GUsbDevice *device) guint16 g_usb_device_get_vid (GUsbDevice *device) { + g_return_val_if_fail (G_USB_IS_DEVICE (device), 0); + return device->priv->desc.idVendor; } @@ -1431,6 +1447,8 @@ g_usb_device_get_vid (GUsbDevice *device) guint16 g_usb_device_get_pid (GUsbDevice *device) { + g_return_val_if_fail (G_USB_IS_DEVICE (device), 0); + return device->priv->desc.idProduct; } @@ -1447,6 +1465,8 @@ g_usb_device_get_pid (GUsbDevice *device) guint8 g_usb_device_get_manufacturer_index (GUsbDevice *device) { + g_return_val_if_fail (G_USB_IS_DEVICE (device), 0); + return device->priv->desc.iManufacturer; } @@ -1463,6 +1483,8 @@ g_usb_device_get_manufacturer_index (GUsbDevice *device) guint8 g_usb_device_get_device_class (GUsbDevice *device) { + g_return_val_if_fail (G_USB_IS_DEVICE (device), 0); + return device->priv->desc.bDeviceClass; } @@ -1480,6 +1502,8 @@ g_usb_device_get_device_class (GUsbDevice *device) guint8 g_usb_device_get_device_subclass (GUsbDevice *device) { + g_return_val_if_fail (G_USB_IS_DEVICE (device), 0); + return device->priv->desc.bDeviceSubClass; } @@ -1497,6 +1521,8 @@ g_usb_device_get_device_subclass (GUsbDevice *device) guint8 g_usb_device_get_device_protocol (GUsbDevice *device) { + g_return_val_if_fail (G_USB_IS_DEVICE (device), 0); + return device->priv->desc.bDeviceProtocol; } @@ -1513,6 +1539,8 @@ g_usb_device_get_device_protocol (GUsbDevice *device) guint8 g_usb_device_get_product_index (GUsbDevice *device) { + g_return_val_if_fail (G_USB_IS_DEVICE (device), 0); + return device->priv->desc.iProduct; } @@ -1529,5 +1557,7 @@ g_usb_device_get_product_index (GUsbDevice *device) guint8 g_usb_device_get_serial_number_index (GUsbDevice *device) { + g_return_val_if_fail (G_USB_IS_DEVICE (device), 0); + return device->priv->desc.iSerialNumber; } |