Skip to content

Commit 73b9ccb

Browse files
iakovQbicz
authored andcommitted
Explicit cast from void* to corresponding type
Fix compilation without -fpermissive
1 parent 7da5cc9 commit 73b9ccb

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

libusb/hid.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ static int return_data(hid_device *dev, unsigned char *data, size_t length);
182182

183183
static hid_device *new_hid_device(void)
184184
{
185-
hid_device *dev = calloc(1, sizeof(hid_device));
185+
hid_device *dev = (hid_device*) calloc(1, sizeof(hid_device));
186186
dev->blocking = 1;
187187

188188
pthread_mutex_init(&dev->mutex, NULL);
@@ -430,7 +430,7 @@ static wchar_t *get_usb_string(libusb_device_handle *dev, uint8_t idx)
430430
431431
Skip over the first character (2-bytes). */
432432
len -= 2;
433-
str = malloc((len / 2 + 1) * sizeof(wchar_t));
433+
str = (wchar_t*) malloc((len / 2 + 1) * sizeof(wchar_t));
434434
int i;
435435
for (i = 0; i < len / 2; i++) {
436436
str[i] = buf[i * 2 + 2] | (buf[i * 2 + 3] << 8);
@@ -563,7 +563,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
563563
struct hid_device_info *tmp;
564564

565565
/* VID/PID match. Create the record. */
566-
tmp = calloc(1, sizeof(struct hid_device_info));
566+
tmp = (struct hid_device_info*) calloc(1, sizeof(struct hid_device_info));
567567
if (cur_dev) {
568568
cur_dev->next = tmp;
569569
}
@@ -736,8 +736,8 @@ static void read_callback(struct libusb_transfer *transfer)
736736

737737
if (transfer->status == LIBUSB_TRANSFER_COMPLETED) {
738738

739-
struct input_report *rpt = malloc(sizeof(*rpt));
740-
rpt->data = malloc(transfer->actual_length);
739+
struct input_report *rpt = (struct input_report*) malloc(sizeof(*rpt));
740+
rpt->data = (uint8_t *) malloc(transfer->actual_length);
741741
memcpy(rpt->data, transfer->buffer, transfer->actual_length);
742742
rpt->len = transfer->actual_length;
743743
rpt->next = NULL;
@@ -799,11 +799,11 @@ static void read_callback(struct libusb_transfer *transfer)
799799
static void *read_thread(void *param)
800800
{
801801
hid_device *dev = param;
802-
unsigned char *buf;
802+
uint8_t *buf;
803803
const size_t length = dev->input_ep_max_packet_size;
804804

805805
/* Set up the transfer object. */
806-
buf = malloc(length);
806+
buf = (uint8_t*) malloc(length);
807807
dev->transfer = libusb_alloc_transfer(0);
808808
libusb_fill_interrupt_transfer(dev->transfer,
809809
dev->device_handle,

linux/hid.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ static __u32 detect_kernel_version(void)
103103

104104
static hid_device *new_hid_device(void)
105105
{
106-
hid_device *dev = calloc(1, sizeof(hid_device));
106+
hid_device *dev = (hid_device*) calloc(1, sizeof(hid_device));
107107
dev->device_handle = -1;
108108
dev->blocking = 1;
109109
dev->uses_numbered_reports = 0;
@@ -122,7 +122,7 @@ static wchar_t *utf8_to_wchar_t(const char *utf8)
122122
if ((size_t) -1 == wlen) {
123123
return wcsdup(L"");
124124
}
125-
ret = calloc(wlen+1, sizeof(wchar_t));
125+
ret = (wchar_t*) calloc(wlen+1, sizeof(wchar_t));
126126
mbstowcs(ret, utf8, wlen+1);
127127
ret[wlen] = 0x0000;
128128
}
@@ -461,7 +461,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
461461
struct hid_device_info *tmp;
462462

463463
/* VID/PID match. Create the record. */
464-
tmp = malloc(sizeof(struct hid_device_info));
464+
tmp = (struct hid_device_info*) malloc(sizeof(struct hid_device_info));
465465
if (cur_dev) {
466466
cur_dev->next = tmp;
467467
}

mac/hid.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ struct hid_device_ {
125125

126126
static hid_device *new_hid_device(void)
127127
{
128-
hid_device *dev = calloc(1, sizeof(hid_device));
128+
hid_device *dev = (hid_device*) calloc(1, sizeof(hid_device));
129129
dev->device_handle = NULL;
130130
dev->blocking = 1;
131131
dev->uses_numbered_reports = 0;
@@ -282,7 +282,7 @@ static int get_product_string(IOHIDDeviceRef device, wchar_t *buf, size_t len)
282282
static wchar_t *dup_wcs(const wchar_t *s)
283283
{
284284
size_t len = wcslen(s);
285-
wchar_t *ret = malloc((len+1)*sizeof(wchar_t));
285+
wchar_t *ret = (wchar_t*) malloc((len+1)*sizeof(wchar_t));
286286
wcscpy(ret, s);
287287

288288
return ret;
@@ -411,7 +411,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
411411

412412
/* Convert the list into a C array so we can iterate easily. */
413413
num_devices = CFSetGetCount(device_set);
414-
IOHIDDeviceRef *device_array = calloc(num_devices, sizeof(IOHIDDeviceRef));
414+
IOHIDDeviceRef *device_array = (IOHIDDeviceRef*) calloc(num_devices, sizeof(IOHIDDeviceRef));
415415
CFSetGetValues(device_set, (const void **) device_array);
416416

417417
/* Iterate over each device, making an entry for it. */
@@ -439,7 +439,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
439439
io_string_t path;
440440

441441
/* VID/PID match. Create the record. */
442-
tmp = malloc(sizeof(struct hid_device_info));
442+
tmp = (struct hid_device_info*) malloc(sizeof(struct hid_device_info));
443443
if (cur_dev) {
444444
cur_dev->next = tmp;
445445
}
@@ -572,8 +572,8 @@ static void hid_report_callback(void *context, IOReturn result, void *sender,
572572
hid_device *dev = context;
573573

574574
/* Make a new Input Report object */
575-
rpt = calloc(1, sizeof(struct input_report));
576-
rpt->data = calloc(1, report_length);
575+
rpt = (input_report*) calloc(1, sizeof(struct input_report));
576+
rpt->data = (uint8_t*) calloc(1, report_length);
577577
memcpy(rpt->data, report, report_length);
578578
rpt->len = report_length;
579579
rpt->next = NULL;
@@ -721,7 +721,7 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)
721721

722722
/* Create the buffers for receiving data */
723723
dev->max_input_report_len = (CFIndex) get_max_report_length(dev->device_handle);
724-
dev->input_report_buf = calloc(dev->max_input_report_len, sizeof(uint8_t));
724+
dev->input_report_buf = (uint8_t*) calloc(dev->max_input_report_len, sizeof(uint8_t));
725725

726726
/* Create the Run Loop Mode for this device.
727727
printing the reference seems to work. */

0 commit comments

Comments
 (0)