diff options
author | Daniel Drake <dsd@gentoo.org> | 2009-06-07 22:19:53 +0100 |
---|---|---|
committer | Daniel Drake <dsd@gentoo.org> | 2009-06-07 22:19:53 +0100 |
commit | 2b3a9ffa776b383cb2dbc3c55e490e32e4c3c22b (patch) | |
tree | 3738f4c72ccb0f4f71ff9d5df0cedd4ad5af2925 | |
parent | cad5cb55c37137e94e35c74fdabfe42a5cbd229b (diff) | |
download | libusb-2b3a9ffa776b383cb2dbc3c55e490e32e4c3c22b.tar.gz |
Eliminate -Wsign-compare compiler warnings
This was due to an API inconsistency which can be safely worked around.
Hopefully we'll remember to fix the API next time we come to break
things.
-rw-r--r-- | libusb/libusb.h | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/libusb/libusb.h b/libusb/libusb.h index 27b3612..b3c9089 100644 --- a/libusb/libusb.h +++ b/libusb/libusb.h @@ -25,6 +25,7 @@ #include <sys/time.h> #include <sys/types.h> #include <time.h> +#include <limits.h> #ifdef __cplusplus extern "C" { @@ -1053,11 +1054,19 @@ static inline unsigned char *libusb_get_iso_packet_buffer( { int i; size_t offset = 0; + int _packet; - if (packet >= transfer->num_iso_packets) + /* oops..slight bug in the API. packet is an unsigned int, but we use + * signed integers almost everywhere else. range-check and convert to + * signed to avoid compiler warnings. FIXME for libusb-2. */ + if (packet > INT_MAX) return NULL; + _packet = packet; - for (i = 0; i < packet; i++) + if (_packet >= transfer->num_iso_packets) + return NULL; + + for (i = 0; i < _packet; i++) offset += transfer->iso_packet_desc[i].length; return transfer->buffer + offset; @@ -1085,10 +1094,19 @@ static inline unsigned char *libusb_get_iso_packet_buffer( static inline unsigned char *libusb_get_iso_packet_buffer_simple( struct libusb_transfer *transfer, unsigned int packet) { - if (packet >= transfer->num_iso_packets) + int _packet; + + /* oops..slight bug in the API. packet is an unsigned int, but we use + * signed integers almost everywhere else. range-check and convert to + * signed to avoid compiler warnings. FIXME for libusb-2. */ + if (packet > INT_MAX) + return NULL; + _packet = packet; + + if (_packet >= transfer->num_iso_packets) return NULL; - return transfer->buffer + (transfer->iso_packet_desc[0].length * packet); + return transfer->buffer + (transfer->iso_packet_desc[0].length * _packet); } /* sync I/O */ |