macOS: silence sprintf deprecation (#509)

This commit is contained in:
Ihor Dutchak
2023-02-19 17:38:04 +02:00
committed by GitHub
parent 4ebce6b505
commit eecbe74bb1
+13 -1
View File
@@ -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
}
}
@@ -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);