Skip to content

Commit

Permalink
descriptor: Fix clang -Wimplicit-int-conversion warnings
Browse files Browse the repository at this point in the history
For the 16-bit case especially, the result of the `or` is implicitly
promoted to `int`, then when returned was warning:

warning: implicit conversion loses integer precision: 'int' to 'uint16_t' (aka 'unsigned short') [-Wimplicit-int-conversion]

Add more casts to shut it up.

Closes libusb#1541
  • Loading branch information
seanm authored and tormodvolden committed Jul 29, 2024
1 parent a319969 commit 8776b80
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions libusb/descriptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@

static inline uint16_t ReadLittleEndian16(const uint8_t p[2])
{
return (uint16_t)p[1] << 8 |
(uint16_t)p[0];
return (uint16_t)((uint16_t)p[1] << 8 |
(uint16_t)p[0]);
}

static inline uint32_t ReadLittleEndian32(const uint8_t p[4])
{
return (uint32_t)p[3] << 24 |
(uint32_t)p[2] << 16 |
(uint32_t)p[1] << 8 |
(uint32_t)p[0];
return (uint32_t)((uint32_t)p[3] << 24 |
(uint32_t)p[2] << 16 |
(uint32_t)p[1] << 8 |
(uint32_t)p[0]);
}

static void clear_endpoint(struct libusb_endpoint_descriptor *endpoint)
Expand Down
2 changes: 1 addition & 1 deletion libusb/version_nano.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define LIBUSB_NANO 11934
#define LIBUSB_NANO 11935

0 comments on commit 8776b80

Please sign in to comment.