Skip to content

Commit

Permalink
DEEPIN: MIPS: loongson64: use strlen to calculate string length
Browse files Browse the repository at this point in the history
Suppress a Clang warning regarding potential buffer overflow:

  arch/mips/loongson64/env.c:190:31: error: the value of the size argument
  in 'strncat' is too large, might lead to a buffer overflow
  [-Werror,-Wstrncat-size]
  190 | strncat(cpu_full_name, freq, sizeof(cpu_full_name));
  | ^~~~~~~~~~~~~~~~~~~~~
  arch/mips/loongson64/env.c:190:31: note: change the argument to be the
  free space in the destination buffer minus the terminating null byte
  190 | strncat(cpu_full_name, freq, sizeof(cpu_full_name));
  | ^~~~~~~~~~~~~~~~~~~~~
  | sizeof(cpu_full_name) - strlen(cpu_full_name) - 1
  1 error generated.

Fixes: "BACKPORT: FROMLIST: MIPS: Add __cpu_full_name[] to make CPU names more human-readable"
Signed-off-by: Mingcong Bai <[email protected]>
  • Loading branch information
MingcongBai committed Dec 25, 2024
1 parent 36bca45 commit cfd4a44
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion arch/mips/loongson64/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ void __init prom_lefi_init_env(void)

/* Append default cpu frequency with round-off */
sprintf(freq, " @ %uMHz", (cpu_clock_freq + 500000) / 1000000);
strncat(cpu_full_name, freq, sizeof(cpu_full_name));
strncat(cpu_full_name, freq, strlen(freq));
__cpu_full_name[0] = cpu_full_name;

/* Read the ID of PCI host bridge to detect bridge type */
Expand Down

0 comments on commit cfd4a44

Please sign in to comment.