Skip to content

Commit

Permalink
mac: replace sprintf uses with snprintf (#511)
Browse files Browse the repository at this point in the history
Reference issue: libusb/hidapi#509
  • Loading branch information
sezero authored Feb 22, 2023
1 parent 438d065 commit 88a0f02
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions mac/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,14 +511,10 @@ static struct hid_device_info *create_device_info_with_usage(IOHIDDeviceRef dev,
/* 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 buffer, but allocate 32 for simple alignment */
cur_dev->path = calloc(1, 32);
const size_t path_len = 32;
cur_dev->path = calloc(1, path_len);
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
snprintf(cur_dev->path, path_len, "DevSrvsID:%llu", entry_id);
}
}

Expand Down Expand Up @@ -988,16 +984,9 @@ 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

snprintf(str, sizeof(str), "HIDAPI_%p", (void*) dev->device_handle);
dev->run_loop_mode =
CFStringCreateWithCString(NULL, str, kCFStringEncodingASCII);

Expand Down

0 comments on commit 88a0f02

Please sign in to comment.