summaryrefslogtreecommitdiff
path: root/libusb/core.c
diff options
context:
space:
mode:
authorPete Batard <pete@akeo.ie>2014-05-16 23:01:57 +0100
committerPete Batard <pete@akeo.ie>2014-05-16 23:01:57 +0100
commitbcc4e517d5ce41e541484ade9b2800ba06a9b903 (patch)
treedc8e64e893606d2371d076d0f712273712e07db6 /libusb/core.c
parent26dab3d6808a00c28a0d222c8f6625d4e719a5b2 (diff)
downloadlibusb-bcc4e517d5ce41e541484ade9b2800ba06a9b903.tar.gz
core: fix/silence issues reported by Coverity
* libusb has been added to Coverity at https://scan.coverity.com/projects/2180 * Use "// coverity[keyword]" to silence the issues we don't care about * All other issues from the Windows build have been fixed, apart from the closing of the DLLs.
Diffstat (limited to 'libusb/core.c')
-rw-r--r--libusb/core.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/libusb/core.c b/libusb/core.c
index ffce020..14417f5 100644
--- a/libusb/core.c
+++ b/libusb/core.c
@@ -775,22 +775,22 @@ int API_EXPORTED libusb_get_port_numbers(libusb_device *dev,
uint8_t* port_numbers, int port_numbers_len)
{
int i = port_numbers_len;
+ struct libusb_context *ctx = DEVICE_CTX(dev);
- while(dev) {
- // HCDs can be listed as devices and would have port #0
- // TODO: see how the other backends want to implement HCDs as parents
- if (dev->port_number == 0)
- break;
- i--;
- if (i < 0) {
- usbi_warn(DEVICE_CTX(dev),
- "port numbers array too small");
+ if (port_numbers_len <= 0)
+ return LIBUSB_ERROR_INVALID_PARAM;
+
+ // HCDs can be listed as devices with port #0
+ while((dev) && (dev->port_number != 0)) {
+ if (--i < 0) {
+ usbi_warn(ctx, "port numbers array is too small");
return LIBUSB_ERROR_OVERFLOW;
}
port_numbers[i] = dev->port_number;
dev = dev->parent_dev;
}
- memmove(port_numbers, &port_numbers[i], port_numbers_len - i);
+ if (i < port_numbers_len)
+ memmove(port_numbers, &port_numbers[i], port_numbers_len - i);
return port_numbers_len - i;
}