Skip to content

Commit 9f13d15

Browse files
Fix size check of max processor count (#199)
On 64-bit systems, size_t will not overflow when the function to get max processors returns UINT32_MAX. Use the appropriate uint32_t type.
1 parent 4e5be9e commit 9f13d15

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/riscv/linux/init.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ void cpuinfo_riscv_linux_init(void) {
244244
* processors. It is not a count of the number of processors on the
245245
* system.
246246
*/
247-
const size_t max_processor_id = 1 +
247+
const uint32_t max_processor_id = 1 +
248248
cpuinfo_linux_get_max_present_processor(
249249
cpuinfo_linux_get_max_processors_count());
250250
if (max_processor_id == 0) {
@@ -260,7 +260,7 @@ void cpuinfo_riscv_linux_init(void) {
260260
riscv_linux_processors = calloc(max_processor_id,
261261
sizeof(struct cpuinfo_riscv_linux_processor));
262262
if (riscv_linux_processors == NULL) {
263-
cpuinfo_log_error("failed to allocate %zu bytes for %zu processors.",
263+
cpuinfo_log_error("failed to allocate %zu bytes for %"PRIu32" processors.",
264264
max_processor_id * sizeof(struct cpuinfo_riscv_linux_processor),
265265
max_processor_id);
266266
goto cleanup;
@@ -479,7 +479,7 @@ void cpuinfo_riscv_linux_init(void) {
479479
linux_cpu_to_processor_map = calloc(max_processor_id,
480480
sizeof(struct cpuinfo_processor*));
481481
if (linux_cpu_to_processor_map == NULL) {
482-
cpuinfo_log_error("failed to allocate %zu bytes for %zu processor map.",
482+
cpuinfo_log_error("failed to allocate %zu bytes for %"PRIu32" processor map.",
483483
max_processor_id * sizeof(struct cpuinfo_processor*),
484484
max_processor_id);
485485
goto cleanup;
@@ -488,7 +488,7 @@ void cpuinfo_riscv_linux_init(void) {
488488
linux_cpu_to_core_map = calloc(max_processor_id,
489489
sizeof(struct cpuinfo_core*));
490490
if (linux_cpu_to_core_map == NULL) {
491-
cpuinfo_log_error("failed to allocate %zu bytes for %zu core map.",
491+
cpuinfo_log_error("failed to allocate %zu bytes for %"PRIu32" core map.",
492492
max_processor_id * sizeof(struct cpuinfo_core*),
493493
max_processor_id);
494494
goto cleanup;
@@ -497,7 +497,7 @@ void cpuinfo_riscv_linux_init(void) {
497497
linux_cpu_to_uarch_index_map = calloc(max_processor_id,
498498
sizeof(struct cpuinfo_uarch_info*));
499499
if (linux_cpu_to_uarch_index_map == NULL) {
500-
cpuinfo_log_error("failed to allocate %zu bytes for %zu uarch map.",
500+
cpuinfo_log_error("failed to allocate %zu bytes for %"PRIu32" uarch map.",
501501
max_processor_id * sizeof(struct cpuinfo_uarch_info*),
502502
max_processor_id);
503503
goto cleanup;

0 commit comments

Comments
 (0)