From 0c1420ef32f44043b8050f27a2843ec2f25d861b Mon Sep 17 00:00:00 2001 From: Kent Russell Date: Thu, 13 Aug 2020 11:01:21 -0400 Subject: [PATCH] Fix GCC warning regarding strncpy in CPU info strlen(src) should not be used as the length in strncpy. Use memcpy since we know the length of the string, and ensure that we NULL-terminate regardless of length Signed-off-by: Kent Russell Change-Id: I21cc6d106510c69464e7ac9d3fc7da3a1e6d1a68 [ROCm/ROCR-Runtime commit: 04f6b9e16bbda987a0afeee396b6892347362a12] --- projects/rocr-runtime/src/topology.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/projects/rocr-runtime/src/topology.c b/projects/rocr-runtime/src/topology.c index 04f3f9ec50..b92342dd6e 100644 --- a/projects/rocr-runtime/src/topology.c +++ b/projects/rocr-runtime/src/topology.c @@ -879,13 +879,10 @@ static HSAKMT_STATUS topology_parse_cpuinfo(struct proc_cpuinfo *cpuinfo, if (!strncmp("model name", read_buf, sizeof("model name") - 1)) { p = strchr(read_buf, ':'); p += 2; /* remove ": " */ - p_len = strlen(p); - if (p_len < HSA_PUBLIC_NAME_SIZE) { - /* -1 to remove \n from p */ - strncpy(cpuinfo[proc].model_name, p, p_len - 1); - cpuinfo[proc].model_name[p_len - 1] = '\0'; - } else - strncpy(cpuinfo[proc].model_name, p, HSA_PUBLIC_NAME_SIZE); + p_len = (strlen(p) > HSA_PUBLIC_NAME_SIZE ? + HSA_PUBLIC_NAME_SIZE : strlen(p)); + memcpy(cpuinfo[proc].model_name, p, p_len); + cpuinfo[proc].model_name[p_len - 1] = '\0'; continue; }