Skip to content

Commit 2891219

Browse files
committed
Explicit cast from void* to corresponding type
Fix compilation without -fpermissive
1 parent d833683 commit 2891219

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
@@ -124,7 +124,7 @@ struct hid_device_ {
124124

125125
static hid_device *new_hid_device(void)
126126
{
127-
hid_device *dev = calloc(1, sizeof(hid_device));
127+
hid_device *dev = (hid_device*) calloc(1, sizeof(hid_device));
128128
dev->device_handle = NULL;
129129
dev->blocking = 1;
130130
dev->uses_numbered_reports = 0;
@@ -281,7 +281,7 @@ static int get_product_string(IOHIDDeviceRef device, wchar_t *buf, size_t len)
281281
static wchar_t *dup_wcs(const wchar_t *s)
282282
{
283283
size_t len = wcslen(s);
284-
wchar_t *ret = malloc((len+1)*sizeof(wchar_t));
284+
wchar_t *ret = (wchar_t*) malloc((len+1)*sizeof(wchar_t));
285285
wcscpy(ret, s);
286286

287287
return ret;
@@ -410,7 +410,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
410410

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

416416
/* Iterate over each device, making an entry for it. */
@@ -437,7 +437,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
437437
io_string_t path;
438438

439439
/* VID/PID match. Create the record. */
440-
tmp = malloc(sizeof(struct hid_device_info));
440+
tmp = (struct hid_device_info*) malloc(sizeof(struct hid_device_info));
441441
if (cur_dev) {
442442
cur_dev->next = tmp;
443443
}
@@ -561,8 +561,8 @@ static void hid_report_callback(void *context, IOReturn result, void *sender,
561561
hid_device *dev = context;
562562

563563
/* Make a new Input Report object */
564-
rpt = calloc(1, sizeof(struct input_report));
565-
rpt->data = calloc(1, report_length);
564+
rpt = (input_report*) calloc(1, sizeof(struct input_report));
565+
rpt->data = (uint8_t*) calloc(1, report_length);
566566
memcpy(rpt->data, report, report_length);
567567
rpt->len = report_length;
568568
rpt->next = NULL;
@@ -710,7 +710,7 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)
710710

711711
/* Create the buffers for receiving data */
712712
dev->max_input_report_len = (CFIndex) get_max_report_length(dev->device_handle);
713-
dev->input_report_buf = calloc(dev->max_input_report_len, sizeof(uint8_t));
713+
dev->input_report_buf = (uint8_t*) calloc(dev->max_input_report_len, sizeof(uint8_t));
714714

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

0 commit comments

Comments
 (0)