Skip to content
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

Explicit cast from void* to corresponding type #4

Merged
merged 6 commits into from
Jun 24, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
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));
iakov marked this conversation as resolved.
Show resolved Hide resolved
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);
Youw marked this conversation as resolved.
Show resolved Hide resolved
iakov marked this conversation as resolved.
Show resolved Hide resolved
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
38 changes: 20 additions & 18 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 @@ -226,7 +226,7 @@ static int get_string_property(IOHIDDeviceRef device, CFStringRef prop, wchar_t
if (!len)
return 0;

str = IOHIDDeviceGetProperty(device, prop);
str = (CFStringRef) IOHIDDeviceGetProperty(device, prop);

buf[0] = 0;

Expand All @@ -239,11 +239,11 @@ static int get_string_property(IOHIDDeviceRef device, CFStringRef prop, wchar_t
len --;

range.location = 0;
range.length = ((size_t)str_len > len)? len: (size_t)str_len;
range.length = ((size_t) str_len > len)? len: (size_t) str_len;
chars_copied = CFStringGetBytes(str,
range,
kCFStringEncodingUTF32LE,
(char)'?',
(char) '?',
FALSE,
(UInt8*)buf,
len * sizeof(wchar_t),
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 All @@ -296,7 +296,8 @@ static wchar_t *dup_wcs(const wchar_t *s)
static io_service_t hidapi_IOHIDDeviceGetService(IOHIDDeviceRef device)
{
static void *iokit_framework = NULL;
static io_service_t (*dynamic_IOHIDDeviceGetService)(IOHIDDeviceRef device) = NULL;
typedef io_service_t (*dynamic_IOHIDDeviceGetService_t)(IOHIDDeviceRef device);
static dynamic_IOHIDDeviceGetService_t dynamic_IOHIDDeviceGetService = NULL;

/* Use dlopen()/dlsym() to get a pointer to IOHIDDeviceGetService() if it exists.
* If any of these steps fail, dynamic_IOHIDDeviceGetService will be left NULL
Expand All @@ -306,7 +307,7 @@ static io_service_t hidapi_IOHIDDeviceGetService(IOHIDDeviceRef device)
iokit_framework = dlopen("/System/Library/IOKit.framework/IOKit", RTLD_LAZY);

if (iokit_framework != NULL)
dynamic_IOHIDDeviceGetService = dlsym(iokit_framework, "IOHIDDeviceGetService");
dynamic_IOHIDDeviceGetService = (dynamic_IOHIDDeviceGetService_t) dlsym(iokit_framework, "IOHIDDeviceGetService");
}

if (dynamic_IOHIDDeviceGetService != NULL) {
Expand Down Expand Up @@ -338,7 +339,7 @@ static io_service_t hidapi_IOHIDDeviceGetService(IOHIDDeviceRef device)
#endif
io_service_t service;
};
struct IOHIDDevice_internal *tmp = (struct IOHIDDevice_internal *)device;
struct IOHIDDevice_internal *tmp = (struct IOHIDDevice_internal *) device;

return tmp->service;
}
Expand Down Expand Up @@ -410,7 +411,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 +438,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 @@ -544,7 +545,7 @@ static void hid_device_removal_callback(void *context, IOReturn result,
void *sender)
{
/* Stop the Run Loop for this device. */
hid_device *d = context;
hid_device *d = (hid_device*) context;

d->disconnected = 1;
CFRunLoopStop(d->run_loop);
Expand All @@ -558,11 +559,11 @@ static void hid_report_callback(void *context, IOReturn result, void *sender,
uint8_t *report, CFIndex report_length)
{
struct input_report *rpt;
hid_device *dev = context;
hid_device *dev = (hid_device*) 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 @@ -605,13 +606,13 @@ static void hid_report_callback(void *context, IOReturn result, void *sender,
hid_close(), and serves to stop the read_thread's run loop. */
static void perform_signal_callback(void *context)
{
hid_device *dev = context;
hid_device *dev = (hid_device*) context;
CFRunLoopStop(dev->run_loop); /*TODO: CFRunLoopGetCurrent()*/
}

static void *read_thread(void *param)
{
hid_device *dev = param;
hid_device *dev = (hid_device*) param;
SInt32 code;

/* Move the device's run loop to this thread. */
Expand Down Expand Up @@ -682,6 +683,7 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)
{
hid_device *dev = NULL;
io_registry_entry_t entry = MACH_PORT_NULL;
IOReturn ret = kIOReturnInvalid;

dev = new_hid_device();

Expand All @@ -704,13 +706,13 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)
}

/* Open the IOHIDDevice */
IOReturn ret = IOHIDDeviceOpen(dev->device_handle, kIOHIDOptionsTypeSeizeDevice);
ret = IOHIDDeviceOpen(dev->device_handle, kIOHIDOptionsTypeSeizeDevice);
if (ret == kIOReturnSuccess) {
char str[32];

/* 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