summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPete Batard <pete@akeo.ie>2012-06-13 13:33:00 +0100
committerPete Batard <pete@akeo.ie>2012-06-13 20:52:24 +0100
commit21ce67310216dd1173a582b584399bf6096965ea (patch)
tree8dfc569fb8a1c7bc445350c40c49f5679208d6f4
parentc38f551e1656bf7810c71d64c4936efc18b9b95a (diff)
Core: Fix Clang warnings
core.c: * Result of 'malloc' is converted to a pointer of type 'struct libusb_device *', which is incompatible with sizeof operand type 'void *' * Memory is never released; potential leak of memory pointed to by 'devs' * Assigned value is garbage or undefined (due to potentially empty and uninitialized device list) descriptor.c: * Function call argument is an uninitialized value io.c: * Call to 'malloc' has an allocation size of 0 bytes * Branch condition evaluates to a garbage value (due to get_next_timeout returning a negative error code instead of zero on error)
-rw-r--r--libusb/core.c3
-rw-r--r--libusb/descriptor.c4
-rw-r--r--libusb/io.c7
-rw-r--r--libusb/version_nano.h2
4 files changed, 10 insertions, 6 deletions
diff --git a/libusb/core.c b/libusb/core.c
index b0fa1c0..1e3edc6 100644
--- a/libusb/core.c
+++ b/libusb/core.c
@@ -609,7 +609,7 @@ ssize_t API_EXPORTED libusb_get_device_list(libusb_context *ctx,
/* convert discovered_devs into a list */
len = discdevs->len;
- ret = malloc(sizeof(void *) * (len + 1));
+ ret = calloc(len + 1, sizeof(struct libusb_device *));
if (!ret) {
len = LIBUSB_ERROR_NO_MEM;
goto out;
@@ -697,6 +697,7 @@ int API_EXPORTED libusb_get_port_path(libusb_context *ctx, libusb_device *dev, u
break;
i--;
if (i < 0) {
+ libusb_free_device_list(devs, 1);
return LIBUSB_ERROR_OVERFLOW;
}
path[i] = dev->port_number;
diff --git a/libusb/descriptor.c b/libusb/descriptor.c
index 763f93c..0c5f51f 100644
--- a/libusb/descriptor.c
+++ b/libusb/descriptor.c
@@ -486,8 +486,10 @@ int API_EXPORTED libusb_get_active_config_descriptor(libusb_device *dev,
if (r < 0)
goto err;
+ _config->wTotalLength = 0;
usbi_parse_descriptor(tmp, "bbw", _config, host_endian);
- buf = malloc(_config->wTotalLength);
+ if (_config->wTotalLength != 0)
+ buf = malloc(_config->wTotalLength);
if (!buf) {
r = LIBUSB_ERROR_NO_MEM;
goto err;
diff --git a/libusb/io.c b/libusb/io.c
index e81ca8b..d06d375 100644
--- a/libusb/io.c
+++ b/libusb/io.c
@@ -1857,7 +1857,7 @@ static int handle_events(struct libusb_context *ctx, struct timeval *tv)
int r;
struct usbi_pollfd *ipollfd;
POLL_NFDS_TYPE nfds = 0;
- struct pollfd *fds;
+ struct pollfd *fds = NULL;
int i = -1;
int timeout_ms;
@@ -1866,7 +1866,8 @@ static int handle_events(struct libusb_context *ctx, struct timeval *tv)
nfds++;
/* TODO: malloc when number of fd's changes, not on every poll */
- fds = malloc(sizeof(*fds) * nfds);
+ if (nfds != 0)
+ fds = malloc(sizeof(*fds) * nfds);
if (!fds) {
usbi_mutex_unlock(&ctx->pollfds_lock);
return LIBUSB_ERROR_NO_MEM;
@@ -2272,7 +2273,7 @@ int API_EXPORTED libusb_get_next_timeout(libusb_context *ctx,
r = usbi_backend->clock_gettime(USBI_CLOCK_MONOTONIC, &cur_ts);
if (r < 0) {
usbi_err(ctx, "failed to read monotonic clock, errno=%d", errno);
- return LIBUSB_ERROR_OTHER;
+ return 0;
}
TIMESPEC_TO_TIMEVAL(&cur_tv, &cur_ts);
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index 9fbea89..32a4fe1 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 10528
+#define LIBUSB_NANO 10529