Skip to content

Commit 88a0f02

Browse files
authored
mac: replace sprintf uses with snprintf (#511)
Reference issue: #509
1 parent 438d065 commit 88a0f02

1 file changed

Lines changed: 4 additions & 15 deletions

File tree

mac/hid.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -511,14 +511,10 @@ static struct hid_device_info *create_device_info_with_usage(IOHIDDeviceRef dev,
511511
/* max value of entry_id(uint64_t) is 18446744073709551615 which is 20 characters long,
512512
so for (max) "path" string 'DevSrvsID:18446744073709551615' we would need
513513
9+1+20+1=31 bytes buffer, but allocate 32 for simple alignment */
514-
cur_dev->path = calloc(1, 32);
514+
const size_t path_len = 32;
515+
cur_dev->path = calloc(1, path_len);
515516
if (cur_dev->path != NULL) {
516-
/* Yes, compiler, we know that snprintf is preferable,
517-
but we're not ready to abandon older macOS-es/SDKs where it is not yet available */
518-
#pragma GCC diagnostic push
519-
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
520-
sprintf(cur_dev->path, "DevSrvsID:%llu", entry_id);
521-
#pragma GCC diagnostic pop
517+
snprintf(cur_dev->path, path_len, "DevSrvsID:%llu", entry_id);
522518
}
523519
}
524520

@@ -988,16 +984,9 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)
988984
dev->max_input_report_len = (CFIndex) get_max_report_length(dev->device_handle);
989985
dev->input_report_buf = (uint8_t*) calloc(dev->max_input_report_len, sizeof(uint8_t));
990986

991-
992-
/* Yes, compiler, we know that snprintf is preferable,
993-
but we're not ready to abandon older macOS-es/SDKs where it is not yet available */
994-
#pragma GCC diagnostic push
995-
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
996987
/* Create the Run Loop Mode for this device.
997988
printing the reference seems to work. */
998-
sprintf(str, "HIDAPI_%p", (void*) dev->device_handle);
999-
#pragma GCC diagnostic pop
1000-
989+
snprintf(str, sizeof(str), "HIDAPI_%p", (void*) dev->device_handle);
1001990
dev->run_loop_mode =
1002991
CFStringCreateWithCString(NULL, str, kCFStringEncodingASCII);
1003992

0 commit comments

Comments
 (0)