Skip to content

Explicit cast from void* to corresponding type #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 24, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions libusb/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ static int return_data(hid_device *dev, unsigned char *data, size_t length);

static hid_device *new_hid_device(void)
{
hid_device *dev = calloc(1, sizeof(hid_device));
hid_device *dev = (hid_device*) calloc(1, sizeof(hid_device));
dev->blocking = 1;

pthread_mutex_init(&dev->mutex, NULL);
Expand Down Expand Up @@ -430,7 +430,7 @@ static wchar_t *get_usb_string(libusb_device_handle *dev, uint8_t idx)

Skip over the first character (2-bytes). */
len -= 2;
str = malloc((len / 2 + 1) * sizeof(wchar_t));
str = (wchar_t*) malloc((len / 2 + 1) * sizeof(wchar_t));
int i;
for (i = 0; i < len / 2; i++) {
str[i] = buf[i * 2 + 2] | (buf[i * 2 + 3] << 8);
Expand Down Expand Up @@ -563,7 +563,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
struct hid_device_info *tmp;

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

if (transfer->status == LIBUSB_TRANSFER_COMPLETED) {

struct input_report *rpt = malloc(sizeof(*rpt));
rpt->data = malloc(transfer->actual_length);
struct input_report *rpt = (struct input_report*) malloc(sizeof(*rpt));
rpt->data = (uint8_t *) malloc(transfer->actual_length);
memcpy(rpt->data, transfer->buffer, transfer->actual_length);
rpt->len = transfer->actual_length;
rpt->next = NULL;
Expand Down Expand Up @@ -799,11 +799,11 @@ static void read_callback(struct libusb_transfer *transfer)
static void *read_thread(void *param)
{
hid_device *dev = param;
unsigned char *buf;
uint8_t *buf;
const size_t length = dev->input_ep_max_packet_size;

/* Set up the transfer object. */
buf = malloc(length);
buf = (uint8_t*) malloc(length);
dev->transfer = libusb_alloc_transfer(0);
libusb_fill_interrupt_transfer(dev->transfer,
dev->device_handle,
Expand Down
6 changes: 3 additions & 3 deletions linux/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static __u32 detect_kernel_version(void)

static hid_device *new_hid_device(void)
{
hid_device *dev = calloc(1, sizeof(hid_device));
hid_device *dev = (hid_device*) calloc(1, sizeof(hid_device));
dev->device_handle = -1;
dev->blocking = 1;
dev->uses_numbered_reports = 0;
Expand All @@ -122,7 +122,7 @@ static wchar_t *utf8_to_wchar_t(const char *utf8)
if ((size_t) -1 == wlen) {
return wcsdup(L"");
}
ret = calloc(wlen+1, sizeof(wchar_t));
ret = (wchar_t*) calloc(wlen+1, sizeof(wchar_t));
mbstowcs(ret, utf8, wlen+1);
ret[wlen] = 0x0000;
}
Expand Down Expand Up @@ -461,7 +461,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
struct hid_device_info *tmp;

/* VID/PID match. Create the record. */
tmp = malloc(sizeof(struct hid_device_info));
tmp = (struct hid_device_info*) malloc(sizeof(struct hid_device_info));
if (cur_dev) {
cur_dev->next = tmp;
}
Expand Down
14 changes: 7 additions & 7 deletions mac/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ struct hid_device_ {

static hid_device *new_hid_device(void)
{
hid_device *dev = calloc(1, sizeof(hid_device));
hid_device *dev = (hid_device*) calloc(1, sizeof(hid_device));
dev->device_handle = NULL;
dev->blocking = 1;
dev->uses_numbered_reports = 0;
Expand Down Expand Up @@ -281,7 +281,7 @@ static int get_product_string(IOHIDDeviceRef device, wchar_t *buf, size_t len)
static wchar_t *dup_wcs(const wchar_t *s)
{
size_t len = wcslen(s);
wchar_t *ret = malloc((len+1)*sizeof(wchar_t));
wchar_t *ret = (wchar_t*) malloc((len+1)*sizeof(wchar_t));
wcscpy(ret, s);

return ret;
Expand Down Expand Up @@ -410,7 +410,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,

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

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

/* VID/PID match. Create the record. */
tmp = malloc(sizeof(struct hid_device_info));
tmp = (struct hid_device_info*) malloc(sizeof(struct hid_device_info));
if (cur_dev) {
cur_dev->next = tmp;
}
Expand Down Expand Up @@ -561,8 +561,8 @@ static void hid_report_callback(void *context, IOReturn result, void *sender,
hid_device *dev = context;

/* Make a new Input Report object */
rpt = calloc(1, sizeof(struct input_report));
rpt->data = calloc(1, report_length);
rpt = (input_report*) calloc(1, sizeof(struct input_report));
rpt->data = (uint8_t*) calloc(1, report_length);
memcpy(rpt->data, report, report_length);
rpt->len = report_length;
rpt->next = NULL;
Expand Down Expand Up @@ -710,7 +710,7 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)

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

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