Skip to content

Commit f6d0073

Browse files
authored
hidraw/libusb: fix -Wall -Wextra -pedantic -Werror compilation (#214)
- minor code-style fixes;
1 parent ffb50af commit f6d0073

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

hidtest/test.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
8/22/2009
88
99
Copyright 2009
10-
10+
1111
This contents of this file may be used by anyone
1212
for any reason without any conditions and may be
1313
used as a starting point for your own applications
@@ -29,18 +29,16 @@
2929

3030
int main(int argc, char* argv[])
3131
{
32+
(void)argc;
33+
(void)argv;
34+
3235
int res;
3336
unsigned char buf[256];
3437
#define MAX_STR 255
3538
wchar_t wstr[MAX_STR];
3639
hid_device *handle;
3740
int i;
3841

39-
#ifdef WIN32
40-
UNREFERENCED_PARAMETER(argc);
41-
UNREFERENCED_PARAMETER(argv);
42-
#endif
43-
4442
struct hid_device_info *devs, *cur_dev;
4543

4644
printf("hidapi test/example tool. Compiled with hidapi version %s, runtime version %s.\n", HID_API_VERSION_STR, hid_version_str());
@@ -55,7 +53,7 @@ int main(int argc, char* argv[])
5553
return -1;
5654

5755
devs = hid_enumerate(0x0, 0x0);
58-
cur_dev = devs;
56+
cur_dev = devs;
5957
while (cur_dev) {
6058
printf("Device Found\n type: %04hx %04hx\n path: %s\n serial_number: %ls", cur_dev->vendor_id, cur_dev->product_id, cur_dev->path, cur_dev->serial_number);
6159
printf("\n");
@@ -73,7 +71,7 @@ int main(int argc, char* argv[])
7371
memset(buf,0x00,sizeof(buf));
7472
buf[0] = 0x01;
7573
buf[1] = 0x81;
76-
74+
7775

7876
// Open the device using the VID, PID,
7977
// and optionally the Serial number.
@@ -115,7 +113,7 @@ int main(int argc, char* argv[])
115113

116114
// Set the hid_read() function to be non-blocking.
117115
hid_set_nonblocking(handle, 1);
118-
116+
119117
// Try to read from the device. There should be no
120118
// data here, but execution should not block.
121119
res = hid_read(handle, buf, 17);
@@ -158,7 +156,7 @@ int main(int argc, char* argv[])
158156
printf("Unable to write()\n");
159157
printf("Error: %ls\n", hid_error(handle));
160158
}
161-
159+
162160

163161
// Request state (cmd 0x81). The first byte is the report number (0x1).
164162
buf[0] = 0x1;

libusb/hid.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,18 +1098,21 @@ static void cleanup_mutex(void *param)
10981098

10991099
int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t length, int milliseconds)
11001100
{
1101-
int bytes_read = -1;
1102-
11031101
#if 0
11041102
int transferred;
11051103
int res = libusb_interrupt_transfer(dev->device_handle, dev->input_endpoint, data, length, &transferred, 5000);
11061104
LOG("transferred: %d\n", transferred);
11071105
return transferred;
11081106
#endif
1107+
/* by initialising this variable right here, GCC gives a compilation warning/error: */
1108+
/* error: variable ‘bytes_read’ might be clobbered by ‘longjmp’ or ‘vfork’ [-Werror=clobbered] */
1109+
int bytes_read; /* = -1; */
11091110

11101111
pthread_mutex_lock(&dev->mutex);
11111112
pthread_cleanup_push(&cleanup_mutex, dev);
11121113

1114+
bytes_read = -1;
1115+
11131116
/* There's an input report queued up. Return it. */
11141117
if (dev->input_reports) {
11151118
/* Return the first one */
@@ -1359,6 +1362,7 @@ int HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *dev, int string_index
13591362

13601363
HID_API_EXPORT const wchar_t * HID_API_CALL hid_error(hid_device *dev)
13611364
{
1365+
(void)dev;
13621366
return L"hid_error is not implemented yet";
13631367
}
13641368

linux/hid.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ static int get_hid_report_descriptor_from_sysfs(const char *sysfs_path, struct h
412412
* strings pointed to by serial_number_utf8 and product_name_utf8 after use.
413413
*/
414414
static int
415-
parse_uevent_info(const char *uevent, int *bus_type,
415+
parse_uevent_info(const char *uevent, unsigned *bus_type,
416416
unsigned short *vendor_id, unsigned short *product_id,
417417
char **serial_number_utf8, char **product_name_utf8)
418418
{
@@ -471,8 +471,8 @@ static int get_device_string(hid_device *dev, enum device_string_id key, wchar_t
471471
struct udev_device *udev_dev, *parent, *hid_dev;
472472
struct stat s;
473473
int ret = -1;
474-
char *serial_number_utf8 = NULL;
475-
char *product_name_utf8 = NULL;
474+
char *serial_number_utf8 = NULL;
475+
char *product_name_utf8 = NULL;
476476

477477
/* Create the udev object */
478478
udev = udev_new();
@@ -495,7 +495,7 @@ static int get_device_string(hid_device *dev, enum device_string_id key, wchar_t
495495
if (hid_dev) {
496496
unsigned short dev_vid;
497497
unsigned short dev_pid;
498-
int bus_type;
498+
unsigned bus_type;
499499
size_t retm;
500500

501501
ret = parse_uevent_info(
@@ -567,8 +567,8 @@ static int get_device_string(hid_device *dev, enum device_string_id key, wchar_t
567567
}
568568

569569
end:
570-
free(serial_number_utf8);
571-
free(product_name_utf8);
570+
free(serial_number_utf8);
571+
free(product_name_utf8);
572572

573573
udev_device_unref(udev_dev);
574574
/* parent and hid_dev don't need to be (and can't be) unref'd.
@@ -647,7 +647,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
647647
unsigned short dev_pid;
648648
char *serial_number_utf8 = NULL;
649649
char *product_name_utf8 = NULL;
650-
int bus_type;
650+
unsigned bus_type;
651651
int result;
652652
struct hidraw_report_descriptor report_desc;
653653

@@ -1046,6 +1046,9 @@ int HID_API_EXPORT hid_get_feature_report(hid_device *dev, unsigned char *data,
10461046
// Not supported by Linux HidRaw yet
10471047
int HID_API_EXPORT HID_API_CALL hid_get_input_report(hid_device *dev, unsigned char *data, size_t length)
10481048
{
1049+
(void)dev;
1050+
(void)data;
1051+
(void)length;
10491052
return -1;
10501053
}
10511054

@@ -1082,6 +1085,10 @@ int HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *dev, wchar_t *s
10821085

10831086
int HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *dev, int string_index, wchar_t *string, size_t maxlen)
10841087
{
1088+
(void)dev;
1089+
(void)string_index;
1090+
(void)string;
1091+
(void)maxlen;
10851092
return -1;
10861093
}
10871094

0 commit comments

Comments
 (0)