Skip to content

Commit 623d387

Browse files
committed
input: align HID adapter slot type with pad_connection_pad_init
GCC on 10.5 PPC warned: iohidmanager_hid.c:691: warning: comparison between signed and unsigned pad_connection_pad_init() at input/connect/joypad_connection.c:397 returns int32_t and can return -1 on allocation failure. Four HID drivers store that return value in an adapter struct field and use it for array indexing. Three got the type wrong: iohidmanager_hid.c : uint32_t slot (warning reported here) btstack_hid.c : uint32_t slot (same structural mismatch, silent - no == -1 check at call site) libusb_hid.c : int slot (compiles clean, but width is implicit rather than explicit) wiiusb_hid.c : int32_t slot (correct) Align all four on int32_t, matching the return type of pad_connection_pad_init and wiiusb_hid.c's precedent. Array-indexing call sites (hid->slots[adapter->slot], hid->hats [adapter->slot][...], etc.) are unaffected - signed and unsigned integer types index arrays identically through integer promotion to ptrdiff_t. The only behavioural effect is that slot == -1 checks (iohidmanager_hid.c:691, libusb_hid.c:313) are now signed/ signed comparisons and actually do what they look like they do. Previously the iohidmanager check "worked" only because the promotion rules happen to coerce (int)-1 to UINT32_MAX for the comparison - accidental correctness.
1 parent 4af8e56 commit 623d387

3 files changed

Lines changed: 8 additions & 3 deletions

File tree

input/drivers_hid/btstack_hid.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ struct btpad_queue_command
681681

682682
struct btstack_hid_adapter
683683
{
684-
uint32_t slot;
684+
int32_t slot;
685685

686686
enum btpad_state state;
687687

input/drivers_hid/iohidmanager_hid.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@ typedef struct apple_hid
4949

5050
struct iohidmanager_hid_adapter
5151
{
52-
uint32_t slot;
52+
/* pad_connection_pad_init() returns int32_t and can return -1 on
53+
* allocation failure. Storing the return in uint32_t compiles
54+
* but makes the `slot == -1` check at the call site a signed/
55+
* unsigned comparison GCC warns about. Matches wiiusb_hid.c's
56+
* adapter struct which got this right. */
57+
int32_t slot;
5358
IOHIDDeviceRef handle;
5459
uint32_t locationId;
5560
char name[NAME_MAX_LENGTH];

input/drivers_hid/libusb_hid.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ struct libusb_adapter
6868
uint8_t name[NAME_MAX_LENGTH];
6969
uint8_t data[2048];
7070

71-
int slot;
71+
int32_t slot;
7272

7373
sthread_t *thread;
7474
slock_t *send_control_lock;

0 commit comments

Comments
 (0)