diff options
author | Pete Batard <pete@akeo.ie> | 2012-06-13 13:33:00 +0100 |
---|---|---|
committer | Pete Batard <pete@akeo.ie> | 2012-06-13 20:52:24 +0100 |
commit | 21ce67310216dd1173a582b584399bf6096965ea (patch) | |
tree | 8dfc569fb8a1c7bc445350c40c49f5679208d6f4 /libusb/io.c | |
parent | c38f551e1656bf7810c71d64c4936efc18b9b95a (diff) | |
download | libusb-21ce67310216dd1173a582b584399bf6096965ea.tar.gz |
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)
Diffstat (limited to 'libusb/io.c')
-rw-r--r-- | libusb/io.c | 7 |
1 files changed, 4 insertions, 3 deletions
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); |