Skip to content

Commit

Permalink
macOS: silence sprintf deprecation (#509)
Browse files Browse the repository at this point in the history
  • Loading branch information
Youw authored Feb 19, 2023
1 parent 4ebce6b commit eecbe74
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion mac/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,10 +510,15 @@ static struct hid_device_info *create_device_info_with_usage(IOHIDDeviceRef dev,
if (res == KERN_SUCCESS) {
/* max value of entry_id(uint64_t) is 18446744073709551615 which is 20 characters long,
so for (max) "path" string 'DevSrvsID:18446744073709551615' we would need
9+1+20+1=31 bytes byffer, but allocate 32 for simple alignment */
9+1+20+1=31 bytes buffer, but allocate 32 for simple alignment */
cur_dev->path = calloc(1, 32);
if (cur_dev->path != NULL) {
/* Yes, compiler, we know that snprintf is preferable,
but we're not ready to abandon older macOS-es/SDKs where it is not yet available */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
sprintf(cur_dev->path, "DevSrvsID:%llu", entry_id);
#pragma GCC diagnostic pop
}
}

Expand Down Expand Up @@ -983,9 +988,16 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)
dev->max_input_report_len = (CFIndex) get_max_report_length(dev->device_handle);
dev->input_report_buf = (uint8_t*) calloc(dev->max_input_report_len, sizeof(uint8_t));


/* Yes, compiler, we know that snprintf is preferable,
but we're not ready to abandon older macOS-es/SDKs where it is not yet available */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
/* Create the Run Loop Mode for this device.
printing the reference seems to work. */
sprintf(str, "HIDAPI_%p", (void*) dev->device_handle);
#pragma GCC diagnostic pop

dev->run_loop_mode =
CFStringCreateWithCString(NULL, str, kCFStringEncodingASCII);

Expand Down

0 comments on commit eecbe74

Please sign in to comment.