GCC_WARN_UNUSED_FUNCTION = YES
GCC_WARN_UNUSED_LABEL = YES
GCC_WARN_UNUSED_VARIABLE = YES
+GCC_WARN_UNUSED_PARAMETER = YES
CLANG_WARN_EMPTY_BODY = YES
CLANG_WARN_CONSTANT_CONVERSION = YES
CLANG_WARN_ENUM_CONVERSION = YES
CLANG_WARN_INT_CONVERSION = YES
CLANG_WARN_DOCUMENTATION_COMMENTS = YES
CLANG_WARN_BOOL_CONVERSION = YES
+CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES
+CLANG_WARN_FLOAT_CONVERSION = YES
+CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES
+CLANG_WARN_INFINITE_RECURSION = YES
+CLANG_WARN_ASSIGN_ENUM = YES
+CLANG_WARN_STRICT_PROTOTYPES = YES
+CLANG_WARN_COMMA = YES
+CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES
// Static analyzer warnings.
CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES
/* Read the target offset (address up to 64KB) */
tmp = buf[7];
buf[7] = 0;
- off = (int)strtoul(buf+3, NULL, 16);
+ off = (unsigned int)strtoul(buf+3, NULL, 16);
buf[7] = tmp;
/* Initialize data_addr */
struct libusb_iso_packet_descriptor *pack = &xfr->iso_packet_desc[i];
if (pack->status != LIBUSB_TRANSFER_COMPLETED) {
- fprintf(stderr, "Error: pack %u status %d\n", i, pack->status);
+ fprintf(stderr, "Error: pack %d status %d\n", i, pack->status);
exit(5);
}
- printf("pack%u length:%u, actual_length:%u\n", i, pack->length, pack->actual_length);
+ printf("pack%d length:%u, actual_length:%u\n", i, pack->length, pack->actual_length);
}
}
}
display_buffer_hex(hid_report_descriptor, descriptor_size);
if ((binary_dump) && ((fd = fopen(binary_name, "w")) != NULL)) {
- if (fwrite(hid_report_descriptor, 1, descriptor_size, fd) != descriptor_size) {
+ if (fwrite(hid_report_descriptor, 1, descriptor_size, fd) != (size_t)descriptor_size) {
printf(" Error writing descriptor to file\n");
}
fclose(fd);
}
/* convert discovered_devs into a list */
- len = discdevs->len;
- ret = calloc(len + 1, sizeof(struct libusb_device *));
+ len = (ssize_t)discdevs->len;
+ ret = calloc((size_t)len + 1, sizeof(struct libusb_device *));
if (!ret) {
len = LIBUSB_ERROR_NO_MEM;
goto out;
return LIBUSB_ERROR_NO_DEVICE;
usbi_mutex_lock(&dev_handle->lock);
- if (dev_handle->claimed_interfaces & (1 << interface_number))
+ if (dev_handle->claimed_interfaces & (1U << interface_number))
goto out;
r = usbi_backend.claim_interface(dev_handle, interface_number);
if (r == 0)
- dev_handle->claimed_interfaces |= 1 << interface_number;
+ dev_handle->claimed_interfaces |= 1U << interface_number;
out:
usbi_mutex_unlock(&dev_handle->lock);
return LIBUSB_ERROR_INVALID_PARAM;
usbi_mutex_lock(&dev_handle->lock);
- if (!(dev_handle->claimed_interfaces & (1 << interface_number))) {
+ if (!(dev_handle->claimed_interfaces & (1U << interface_number))) {
r = LIBUSB_ERROR_NOT_FOUND;
goto out;
}
r = usbi_backend.release_interface(dev_handle, interface_number);
if (r == 0)
- dev_handle->claimed_interfaces &= ~(1 << interface_number);
+ dev_handle->claimed_interfaces &= ~(1U << interface_number);
out:
usbi_mutex_unlock(&dev_handle->lock);
return LIBUSB_ERROR_NO_DEVICE;
}
- if (!(dev_handle->claimed_interfaces & (1 << interface_number))) {
+ if (!(dev_handle->claimed_interfaces & (1U << interface_number))) {
usbi_mutex_unlock(&dev_handle->lock);
return LIBUSB_ERROR_NOT_FOUND;
}
case LIBUSB_LOG_LEVEL_DEBUG: syslog_level = LOG_DEBUG; break;
}
syslog(syslog_level, "%s", str);
-#else /* All of gcc, Clang, XCode seem to use #warning */
+#else /* All of gcc, Clang, Xcode seem to use #warning */
#warning System logging is not supported on this platform. Logging to stderr will be used instead.
fputs(str, stderr);
#endif
if (global_debug) {
header_len = snprintf(buf, sizeof(buf),
- "[%2d.%06d] [%08x] libusb: %s [%s] ",
- (int)now.tv_sec, (int)(now.tv_nsec / 1000L), usbi_get_tid(), prefix, function);
+ "[%2ld.%06ld] [%08x] libusb: %s [%s] ",
+ (long)now.tv_sec, (long)(now.tv_nsec / 1000L), usbi_get_tid(), prefix, function);
} else {
header_len = snprintf(buf, sizeof(buf),
"libusb: %s [%s] ", prefix, function);
}
/* Make sure buffer is NUL terminated */
buf[header_len] = '\0';
- text_len = vsnprintf(buf + header_len, sizeof(buf) - header_len,
+ text_len = vsnprintf(buf + header_len, sizeof(buf) - (size_t)header_len,
format, args);
if (text_len < 0 || text_len + header_len >= (int)sizeof(buf)) {
/* Truncated log output. On some platforms a -1 return value means
* that the output was truncated. */
- text_len = sizeof(buf) - header_len;
+ text_len = (int)sizeof(buf) - header_len;
}
- if (header_len + text_len + sizeof(USBI_LOG_LINE_END) >= sizeof(buf)) {
+ if (header_len + text_len + (int)sizeof(USBI_LOG_LINE_END) >= (int)sizeof(buf)) {
/* Need to truncate the text slightly to fit on the terminator. */
- text_len -= (header_len + text_len + sizeof(USBI_LOG_LINE_END)) - sizeof(buf);
+ text_len -= (header_len + text_len + (int)sizeof(USBI_LOG_LINE_END)) - (int)sizeof(buf);
}
strcpy(buf + header_len + text_len, USBI_LOG_LINE_END);
if (host_endian) {
memcpy(dp, sp, 2);
} else {
- w = (sp[1] << 8) | sp[0];
+ w = (uint16_t)((sp[1] << 8) | sp[0]);
*((uint16_t *)dp) = w;
}
sp += 2;
if (host_endian) {
memcpy(dp, sp, 4);
} else {
- d = (sp[3] << 24) | (sp[2] << 16) |
- (sp[1] << 8) | sp[0];
+ d = (uint32_t)((sp[3] << 24) | (sp[2] << 16) |
+ (sp[1] << 8) | sp[0]);
*((uint32_t *)dp) = d;
}
sp += 4;
/* Copy any unknown descriptors into a storage area for drivers */
/* to later parse */
len = (int)(buffer - begin);
- if (!len) {
+ if (len <= 0) {
endpoint->extra = NULL;
endpoint->extra_length = 0;
return parsed;
}
- extra = malloc(len);
+ extra = malloc((size_t)len);
endpoint->extra = extra;
if (!extra) {
endpoint->extra_length = 0;
(struct libusb_interface_descriptor *) usb_interface->altsetting;
altsetting = usbi_reallocf(altsetting,
sizeof(struct libusb_interface_descriptor) *
- (usb_interface->num_altsetting + 1));
+ ((size_t)usb_interface->num_altsetting + 1));
if (!altsetting) {
r = LIBUSB_ERROR_NO_MEM;
goto err;
/* Copy any unknown descriptors into a storage area for */
/* drivers to later parse */
len = (int)(buffer - begin);
- if (len) {
- ifp->extra = malloc(len);
+ if (len > 0) {
+ ifp->extra = malloc((size_t)len);
if (!ifp->extra) {
r = LIBUSB_ERROR_NO_MEM;
goto err;
/* Copy any unknown descriptors into a storage area for */
/* drivers to later parse */
len = (int)(buffer - begin);
- if (len) {
+ if (len > 0) {
/* FIXME: We should realloc and append here */
if (!config->extra_length) {
- config->extra = malloc(len);
+ config->extra = malloc((size_t)len);
if (!config->extra) {
r = LIBUSB_ERROR_NO_MEM;
goto err;
if (r < 4)
return LIBUSB_ERROR_IO;
- langid = tbuf[2] | (tbuf[3] << 8);
+ langid = (uint16_t)(tbuf[2] | (tbuf[3] << 8));
r = libusb_get_string_descriptor(dev_handle, desc_index, langid, tbuf,
sizeof(tbuf));
*/
/* The vendor_id field is valid for matching */
- USBI_HOTPLUG_VENDOR_ID_VALID = (1 << 3),
+ USBI_HOTPLUG_VENDOR_ID_VALID = (1U << 3),
/* The product_id field is valid for matching */
- USBI_HOTPLUG_PRODUCT_ID_VALID = (1 << 4),
+ USBI_HOTPLUG_PRODUCT_ID_VALID = (1U << 4),
/* The dev_class field is valid for matching */
- USBI_HOTPLUG_DEV_CLASS_VALID = (1 << 5),
+ USBI_HOTPLUG_DEV_CLASS_VALID = (1U << 5),
/* This callback has been unregistered and needs to be freed */
- USBI_HOTPLUG_NEEDS_FREE = (1 << 6),
+ USBI_HOTPLUG_NEEDS_FREE = (1U << 6),
};
/** \ingroup hotplug
* use it on a non-isochronous endpoint. If you do this, ensure that at time
* of submission, num_iso_packets is 0 and that type is set appropriately.
*
- * \param iso_packets number of isochronous packet descriptors to allocate
+ * \param iso_packets number of isochronous packet descriptors to allocate. Must be non-negative.
* \returns a newly allocated transfer, or NULL on error
*/
DEFAULT_VISIBILITY
int iso_packets)
{
struct libusb_transfer *transfer;
- size_t os_alloc_size = usbi_backend.transfer_priv_size;
- size_t alloc_size = sizeof(struct usbi_transfer)
+ size_t os_alloc_size;
+ size_t alloc_size;
+ struct usbi_transfer *itransfer;
+
+ assert(iso_packets >= 0);
+
+ os_alloc_size = usbi_backend.transfer_priv_size;
+ alloc_size = sizeof(struct usbi_transfer)
+ sizeof(struct libusb_transfer)
- + (sizeof(struct libusb_iso_packet_descriptor) * iso_packets)
+ + (sizeof(struct libusb_iso_packet_descriptor) * (size_t)iso_packets)
+ os_alloc_size;
- struct usbi_transfer *itransfer = calloc(1, alloc_size);
+ itransfer = calloc(1, alloc_size);
if (!itransfer)
return NULL;
* it will store them here, should you wish to parse them. */
const unsigned char *extra;
- /** Length of the extra descriptors, in bytes. */
+ /** Length of the extra descriptors, in bytes. Must be non-negative. */
int extra_length;
};
* it will store them here, should you wish to parse them. */
const unsigned char *extra;
- /** Length of the extra descriptors, in bytes. */
+ /** Length of the extra descriptors, in bytes. Must be non-negative. */
int extra_length;
};
* by the num_altsetting field. */
const struct libusb_interface_descriptor *altsetting;
- /** The number of alternate settings that belong to this interface */
+ /** The number of alternate settings that belong to this interface.
+ * Must be non-negative. */
int num_altsetting;
};
* descriptors, it will store them here, should you wish to parse them. */
const unsigned char *extra;
- /** Length of the extra descriptors, in bytes. */
+ /** Length of the extra descriptors, in bytes. Must be non-negative. */
int extra_length;
};
* libusb_transfer.flags values */
enum libusb_transfer_flags {
/** Report short frames as errors */
- LIBUSB_TRANSFER_SHORT_NOT_OK = 1<<0,
+ LIBUSB_TRANSFER_SHORT_NOT_OK = 1U << 0,
/** Automatically free() transfer buffer during libusb_free_transfer().
* Note that buffers allocated with libusb_dev_mem_alloc() should not
* be attempted freed in this way, since free() is not an appropriate
* way to release such memory. */
- LIBUSB_TRANSFER_FREE_BUFFER = 1<<1,
+ LIBUSB_TRANSFER_FREE_BUFFER = 1U << 1,
/** Automatically call libusb_free_transfer() after callback returns.
* If this flag is set, it is illegal to call libusb_free_transfer()
* from your transfer callback, as this will result in a double-free
* when this flag is acted upon. */
- LIBUSB_TRANSFER_FREE_TRANSFER = 1<<2,
+ LIBUSB_TRANSFER_FREE_TRANSFER = 1U << 2,
/** Terminate transfers that are a multiple of the endpoint's
* wMaxPacketSize with an extra zero length packet. This is useful
*
* Available since libusb-1.0.9.
*/
- LIBUSB_TRANSFER_ADD_ZERO_PACKET = 1 << 3,
+ LIBUSB_TRANSFER_ADD_ZERO_PACKET = 1U << 3,
};
/** \ingroup libusb_asyncio
* to determine if errors occurred. */
enum libusb_transfer_status status;
- /** Length of the data buffer */
+ /** Length of the data buffer. Must be non-negative. */
int length;
/** Actual length of data that was transferred. Read-only, and only for
unsigned char *buffer;
/** Number of isochronous packets. Only used for I/O with isochronous
- * endpoints. */
+ * endpoints. Must be non-negative. */
int num_iso_packets;
/** Isochronous packet descriptors, for isochronous transfers only. */
* Flags for hotplug events */
typedef enum {
/** Default value when not using any flags. */
- LIBUSB_HOTPLUG_NO_FLAGS = 0,
+ LIBUSB_HOTPLUG_NO_FLAGS = 0U,
/** Arm the callback and fire it for all matching currently attached devices. */
- LIBUSB_HOTPLUG_ENUMERATE = 1<<0,
+ LIBUSB_HOTPLUG_ENUMERATE = 1U << 0,
} libusb_hotplug_flag;
/** \ingroup libusb_hotplug
* Hotplug events */
typedef enum {
/** A device has been plugged in and is ready to use */
- LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED = 0x01,
+ LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED = 0x01U,
/** A device has left and is no longer available.
* It is the user's responsibility to call libusb_close on any handle associated with a disconnected device.
* It is safe to call libusb_get_device_descriptor on a device that has left */
- LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT = 0x02,
+ LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT = 0x02U,
} libusb_hotplug_event;
/** \ingroup libusb_hotplug
#include <config.h>
#include <stdlib.h>
-
+#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <time.h>
enum usbi_event_flags {
/* The list of pollfds has been modified */
- USBI_EVENT_POLLFDS_MODIFIED = 1 << 0,
+ USBI_EVENT_POLLFDS_MODIFIED = 1U << 0,
/* The user has interrupted the event handler */
- USBI_EVENT_USER_INTERRUPT = 1 << 1,
+ USBI_EVENT_USER_INTERRUPT = 1U << 1,
/* A hotplug callback deregistration is pending */
- USBI_EVENT_HOTPLUG_CB_DEREGISTERED = 1 << 2,
+ USBI_EVENT_HOTPLUG_CB_DEREGISTERED = 1U << 2,
};
/* Macros for managing event handling state */
enum usbi_transfer_state_flags {
/* Transfer successfully submitted by backend */
- USBI_TRANSFER_IN_FLIGHT = 1 << 0,
+ USBI_TRANSFER_IN_FLIGHT = 1U << 0,
/* Cancellation was requested via libusb_cancel_transfer() */
- USBI_TRANSFER_CANCELLING = 1 << 1,
+ USBI_TRANSFER_CANCELLING = 1U << 1,
/* Operation on the transfer failed because the device disappeared */
- USBI_TRANSFER_DEVICE_DISAPPEARED = 1 << 2,
+ USBI_TRANSFER_DEVICE_DISAPPEARED = 1U << 2,
};
enum usbi_transfer_timeout_flags {
/* Set by backend submit_transfer() if the OS handles timeout */
- USBI_TRANSFER_OS_HANDLES_TIMEOUT = 1 << 0,
+ USBI_TRANSFER_OS_HANDLES_TIMEOUT = 1U << 0,
/* The transfer timeout has been handled */
- USBI_TRANSFER_TIMEOUT_HANDLED = 1 << 1,
+ USBI_TRANSFER_TIMEOUT_HANDLED = 1U << 1,
/* The transfer timeout was successfully processed */
- USBI_TRANSFER_TIMED_OUT = 1 << 2,
+ USBI_TRANSFER_TIMED_OUT = 1U << 2,
};
#define USBI_TRANSFER_TO_LIBUSB_TRANSFER(transfer) \
static inline void *usbi_transfer_get_os_priv(struct usbi_transfer *transfer)
{
+ assert(transfer->num_iso_packets >= 0);
return ((unsigned char *)transfer) + sizeof(struct usbi_transfer)
+ sizeof(struct libusb_transfer)
- + (transfer->num_iso_packets
+ + ((size_t)transfer->num_iso_packets
* sizeof(struct libusb_iso_packet_descriptor));
}
*/
#include "config.h"
+#include <assert.h>
#include <time.h>
#include <ctype.h>
#include <errno.h>
/* current interface */
struct darwin_interface *cInterface;
- int8_t i, iface;
+ uint8_t i, iface;
usbi_dbg ("converting ep address 0x%02x to pipeRef and interface", ep);
for (iface = 0 ; iface < USB_MAXINTERFACES ; iface++) {
cInterface = &priv->interfaces[iface];
- if (dev_handle->claimed_interfaces & (1 << iface)) {
+ if (dev_handle->claimed_interfaces & (1U << iface)) {
for (i = 0 ; i < cInterface->num_endpoints ; i++) {
if (cInterface->endpoint_addrs[i] == ep) {
*pipep = i + 1;
if (config_index < 0)
return config_index;
- return darwin_get_config_descriptor (dev, config_index, buffer, len, host_endian);
+ assert(config_index >= 0 && config_index <= UINT8_MAX);
+ return darwin_get_config_descriptor (dev, (UInt8)config_index, buffer, len, host_endian);
}
static int darwin_get_config_descriptor(struct libusb_device *dev, uint8_t config_index, unsigned char *buffer, size_t len, int *host_endian) {
static IOReturn darwin_request_descriptor (usb_device_t **device, UInt8 desc, UInt8 desc_index, void *buffer, size_t buffer_size) {
IOUSBDevRequestTO req;
+ assert(buffer_size <= UINT16_MAX);
+
memset (buffer, 0, buffer_size);
/* Set up request for descriptor/ */
req.bmRequestType = USBmakebmRequestType(kUSBIn, kUSBStandard, kUSBDevice);
req.bRequest = kUSBRqGetDescriptor;
- req.wValue = desc << 8;
+ req.wValue = (UInt16)(desc << 8);
req.wIndex = desc_index;
- req.wLength = buffer_size;
+ req.wLength = (UInt16)buffer_size;
req.pData = buffer;
req.noDataTimeout = 20;
req.completionTimeout = 100;
static enum libusb_error darwin_cache_device_descriptor (struct libusb_context *ctx, struct darwin_cached_device *dev) {
usb_device_t **device = dev->device;
- int retries = 1, delay = 30000;
+ int retries = 1;
+ long delay = 30000; // microseconds
int unsuspended = 0, try_unsuspend = 1, try_reconfigure = 1;
int is_open = 0;
IOReturn ret = 0, ret2;
(void)(*device)->GetUSBDeviceInformation (device, &info);
/* note that the device was suspended */
- if (info & (1 << kUSBInformationDeviceIsSuspendedBit) || 0 == info)
+ if (info & (1U << kUSBInformationDeviceIsSuspendedBit) || 0 == info)
try_unsuspend = 1;
#endif
}
if (kIOReturnSuccess != ret) {
- usbi_dbg("kernel responded with code: 0x%08x. sleeping for %d ms before trying again", ret, delay/1000);
+ usbi_dbg("kernel responded with code: 0x%08x. sleeping for %ld ms before trying again", ret, delay/1000);
/* sleep for a little while before trying again */
- nanosleep(&(struct timespec){delay / 1000000, (delay * 1000) % 1000000000UL}, NULL);
+ nanosleep(&(struct timespec){delay / 1000000, (delay * 1000) % 1000000000}, NULL);
}
} while (kIOReturnSuccess != ret && retries--);
}
dev->port_number = cached_device->port;
dev->bus_number = cached_device->location >> 24;
- dev->device_address = cached_device->address;
+ assert(cached_device->address <= UINT8_MAX);
+ dev->device_address = (uint8_t)cached_device->address;
(*(priv->dev->device))->GetDeviceSpeed (priv->dev->device, &devSpeed);
/* make sure all interfaces are released */
for (i = 0 ; i < USB_MAXINTERFACES ; i++)
- if (dev_handle->claimed_interfaces & (1 << i))
+ if (dev_handle->claimed_interfaces & (1U << i))
libusb_release_interface (dev_handle, i);
if (0 == dpriv->open_count) {
IOReturn kresult;
int i;
+ assert(config >= 0 && config <= UINT8_MAX);
+
/* Setting configuration will invalidate the interface, so we need
to reclaim it. First, dispose of existing interfaces, if any. */
for (i = 0 ; i < USB_MAXINTERFACES ; i++)
- if (dev_handle->claimed_interfaces & (1 << i))
+ if (dev_handle->claimed_interfaces & (1U << i))
darwin_release_interface (dev_handle, i);
- kresult = (*(dpriv->device))->SetConfiguration (dpriv->device, config);
+ kresult = (*(dpriv->device))->SetConfiguration (dpriv->device, (UInt8)config);
if (kresult != kIOReturnSuccess)
return darwin_to_libusb (kresult);
/* Reclaim any interfaces. */
for (i = 0 ; i < USB_MAXINTERFACES ; i++)
- if (dev_handle->claimed_interfaces & (1 << i))
+ if (dev_handle->claimed_interfaces & (1U << i))
darwin_claim_interface (dev_handle, i);
- dpriv->active_config = config;
+ dpriv->active_config = (UInt8)config;
return LIBUSB_SUCCESS;
}
}
/* iterate through pipe references */
- for (int i = 1 ; i <= numep ; i++) {
+ for (UInt8 i = 1 ; i <= numep ; i++) {
kresult = (*(cInterface->interface))->GetPipeProperties(cInterface->interface, i, &direction, &number, &dont_care1,
&dont_care2, &dont_care3);
cInterface->endpoint_addrs[i - 1] = endpoint_desc->bEndpointAddress;
} else {
- cInterface->endpoint_addrs[i - 1] = (((kUSBIn == direction) << kUSBRqDirnShift) | (number & LIBUSB_ENDPOINT_ADDRESS_MASK));
+ cInterface->endpoint_addrs[i - 1] = (UInt8)(((kUSBIn == direction) << kUSBRqDirnShift) | (number & LIBUSB_ENDPOINT_ADDRESS_MASK));
}
usbi_dbg ("interface: %i pipe %i: dir: %i number: %i", iface, i, cInterface->endpoint_addrs[i - 1] >> kUSBRqDirnShift,
IOCFPlugInInterface **plugInInterface = NULL;
SInt32 score;
+ assert(iface >= 0 && iface <= UINT8_MAX);
+
/* current interface */
struct darwin_interface *cInterface = &priv->interfaces[iface];
- kresult = darwin_get_interface (dpriv->device, iface, &usbInterface);
+ kresult = darwin_get_interface (dpriv->device, (uint8_t)iface, &usbInterface);
if (kresult != kIOReturnSuccess)
return darwin_to_libusb (kresult);
return ret;
}
- kresult = darwin_get_interface (dpriv->device, iface, &usbInterface);
+ kresult = darwin_get_interface (dpriv->device, (uint8_t)iface, &usbInterface);
if (kresult != kIOReturnSuccess) {
usbi_err (HANDLE_CTX (dev_handle), "darwin_get_interface: %s", darwin_error_str(kresult));
return darwin_to_libusb (kresult);
if (!cInterface->interface)
return LIBUSB_ERROR_NO_DEVICE;
- kresult = (*(cInterface->interface))->SetAlternateInterface (cInterface->interface, altsetting);
+ assert(altsetting >= 0 && altsetting <= UINT8_MAX);
+ kresult = (*(cInterface->interface))->SetAlternateInterface (cInterface->interface, (UInt8)altsetting);
if (kresult != kIOReturnSuccess)
darwin_reset_device (dev_handle);
IOUSBConfigurationDescriptor configuration;
bool reenumerate = false;
IOReturn kresult;
- int i;
+ UInt8 i;
/* from macOS 10.11 ResetDevice no longer does anything so just use USBDeviceReEnumerate */
kresult = (*(dpriv->device))->USBDeviceReEnumerate (dpriv->device, 0);
CFTypeRef driver;
IOReturn kresult;
- kresult = darwin_get_interface (dpriv->device, interface, &usbInterface);
+ assert(interface >= 0 && interface <= UINT8_MAX);
+ kresult = darwin_get_interface (dpriv->device, (uint8_t)interface, &usbInterface);
if (kresult != kIOReturnSuccess) {
usbi_err (HANDLE_CTX (dev_handle), "darwin_get_interface: %s", darwin_error_str(kresult));
if (transferType == kUSBInterrupt) {
if (IS_XFERIN(transfer))
ret = (*(cInterface->interface))->ReadPipeAsync(cInterface->interface, pipeRef, transfer->buffer,
- transfer->length, darwin_async_io_callback, itransfer);
+ (UInt32)transfer->length, darwin_async_io_callback, itransfer);
else
ret = (*(cInterface->interface))->WritePipeAsync(cInterface->interface, pipeRef, transfer->buffer,
- transfer->length, darwin_async_io_callback, itransfer);
+ (UInt32)transfer->length, darwin_async_io_callback, itransfer);
} else {
itransfer->timeout_flags |= USBI_TRANSFER_OS_HANDLES_TIMEOUT;
if (IS_XFERIN(transfer))
ret = (*(cInterface->interface))->ReadPipeAsyncTO(cInterface->interface, pipeRef, transfer->buffer,
- transfer->length, transfer->timeout, transfer->timeout,
- darwin_async_io_callback, (void *)itransfer);
+ (UInt32)transfer->length, transfer->timeout, transfer->timeout,
+ darwin_async_io_callback, itransfer);
else
ret = (*(cInterface->interface))->WritePipeAsyncTO(cInterface->interface, pipeRef, transfer->buffer,
- transfer->length, transfer->timeout, transfer->timeout,
- darwin_async_io_callback, (void *)itransfer);
+ (UInt32)transfer->length, transfer->timeout, transfer->timeout,
+ darwin_async_io_callback, itransfer);
}
if (ret)
if (IS_XFERIN(transfer))
ret = (*(cInterface->interface))->ReadStreamsPipeAsyncTO(cInterface->interface, pipeRef, itransfer->stream_id,
- transfer->buffer, transfer->length, transfer->timeout,
- transfer->timeout, darwin_async_io_callback, (void *)itransfer);
+ transfer->buffer, (UInt32)transfer->length, transfer->timeout,
+ transfer->timeout, darwin_async_io_callback, itransfer);
else
ret = (*(cInterface->interface))->WriteStreamsPipeAsyncTO(cInterface->interface, pipeRef, itransfer->stream_id,
- transfer->buffer, transfer->length, transfer->timeout,
- transfer->timeout, darwin_async_io_callback, (void *)itransfer);
+ transfer->buffer, (UInt32)transfer->length, transfer->timeout,
+ transfer->timeout, darwin_async_io_callback, itransfer);
if (ret)
usbi_err (TRANSFER_CTX (transfer), "bulk stream transfer failed (dir = %s): %s (code = 0x%08x)", IS_XFERIN(transfer) ? "In" : "Out",
if (!tpriv->isoc_framelist) {
tpriv->num_iso_packets = transfer->num_iso_packets;
- tpriv->isoc_framelist = (IOUSBIsocFrame*) calloc (transfer->num_iso_packets, sizeof(IOUSBIsocFrame));
+ tpriv->isoc_framelist = (IOUSBIsocFrame*) calloc ((size_t)transfer->num_iso_packets, sizeof(IOUSBIsocFrame));
if (!tpriv->isoc_framelist)
return LIBUSB_ERROR_NO_MEM;
}
/* copy the frame list from the libusb descriptor (the structures differ only is member order) */
- for (i = 0 ; i < transfer->num_iso_packets ; i++)
- tpriv->isoc_framelist[i].frReqCount = transfer->iso_packet_desc[i].length;
+ for (i = 0 ; i < transfer->num_iso_packets ; i++) {
+ unsigned int length = transfer->iso_packet_desc[i].length;
+ assert(length <= UINT16_MAX);
+ tpriv->isoc_framelist[i].frReqCount = (UInt16)length;
+ }
/* determine the interface/endpoint to use */
if (ep_to_pipeRef (transfer->dev_handle, transfer->endpoint, &pipeRef, NULL, &cInterface) != 0) {
/* submit the request */
if (IS_XFERIN(transfer))
kresult = (*(cInterface->interface))->ReadIsochPipeAsync(cInterface->interface, pipeRef, transfer->buffer, frame,
- transfer->num_iso_packets, tpriv->isoc_framelist, darwin_async_io_callback,
+ (UInt32)transfer->num_iso_packets, tpriv->isoc_framelist, darwin_async_io_callback,
itransfer);
else
kresult = (*(cInterface->interface))->WriteIsochPipeAsync(cInterface->interface, pipeRef, transfer->buffer, frame,
- transfer->num_iso_packets, tpriv->isoc_framelist, darwin_async_io_callback,
+ (UInt32)transfer->num_iso_packets, tpriv->isoc_framelist, darwin_async_io_callback,
itransfer);
if (LIBUSB_SPEED_FULL == transfer->dev_handle->dev->speed)
/* Full speed */
- cInterface->frames[transfer->endpoint] = frame + transfer->num_iso_packets * (1 << (interval - 1));
+ cInterface->frames[transfer->endpoint] = frame + (UInt32)transfer->num_iso_packets * (1U << (interval - 1));
else
/* High/super speed */
- cInterface->frames[transfer->endpoint] = frame + transfer->num_iso_packets * (1 << (interval - 1)) / 8;
+ cInterface->frames[transfer->endpoint] = frame + (UInt32)transfer->num_iso_packets * (1U << (interval - 1)) / 8;
if (kresult != kIOReturnSuccess) {
usbi_err (TRANSFER_CTX (transfer), "isochronous transfer failed (dir: %s): %s", IS_XFERIN(transfer) ? "In" : "Out",
return darwin_to_libusb(rc);
}
- return num_streams;
+ assert(num_streams <= INT_MAX);
+ return (int)num_streams;
}
static int darwin_free_streams (struct libusb_device_handle *dev_handle, unsigned char *endpoints, int num_endpoints) {
UInt32 location;
UInt64 parent_session;
UInt64 session;
- UInt16 address;
+ USBDeviceAddress address;
char sys_path[21];
usb_device_t **device;
int open_count;
if (fRawFD > 0)
close(fRawFD);
for(int i = 0; i < 32; i++) {
- if (fClaimedInterfaces & (1 << i))
+ if (fClaimedInterfaces & (1U << i))
ReleaseInterface(i);
}
delete_sem(fTransfersSem);
{
int status = fUSBDevice->ClaimInterface(inumber);
if (status == LIBUSB_SUCCESS)
- fClaimedInterfaces |= (1 << inumber);
+ fClaimedInterfaces |= (1U << inumber);
return status;
}
USBDeviceHandle::ReleaseInterface(int inumber)
{
fUSBDevice->ReleaseInterface(inumber);
- fClaimedInterfaces &= ~(1 << inumber);
+ fClaimedInterfaces &= ~(1U << inumber);
return LIBUSB_SUCCESS;
}
{
if (interface > ActiveConfiguration()->number_interfaces)
return LIBUSB_ERROR_NOT_FOUND;
- if (fClaimedInterfaces & (1 << interface))
+ if (fClaimedInterfaces & (1U << interface))
return LIBUSB_ERROR_BUSY;
- fClaimedInterfaces |= (1 << interface);
+ fClaimedInterfaces |= (1U << interface);
return LIBUSB_SUCCESS;
}
int USBDevice::ReleaseInterface(int interface)
{
- fClaimedInterfaces &= ~(1 << interface);
+ fClaimedInterfaces &= ~(1U << interface);
return LIBUSB_SUCCESS;
}
-#define LIBUSB_NANO 11343
+#define LIBUSB_NANO 11344