wsl/hsakmt: Resolve snprintf Truncation Warning

This patch addresses a warning encountered during the build process:
warning: ‘%s’ directive output may be truncated writing up to 255 bytes into a
region of size between 0 and 544 [-Wformat-truncation=]
     snprintf(path, MAXPATHSIZE, "%s/%s/cache", node_dir, dir->d_name);
                                     ^~
note: ‘snprintf’ output between 8 and 807 bytes into a destination of size 545
     snprintf(path, MAXPATHSIZE, "%s/%s/cache", node_dir, dir->d_name);
     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Horatio Zhang <Hongkun.Zhang@amd.com>
Reviewed-by: Aaron Liu <aaron.liu@amd.com>
Part-of: <http://10.67.69.192/wsl/libhsakmt/-/merge_requests/38>
Этот коммит содержится в:
Horatio Zhang
2024-09-29 17:02:18 +08:00
коммит произвёл Frank Min
родитель 263623c198
Коммит 5cd49fb600
+8 -1
Просмотреть файл
@@ -870,7 +870,14 @@ topology_create_temp_cpu_cache_list(int node, struct proc_cpuinfo *cpuinfo,
continue;
if (!isdigit(dir->d_name[3])) /* ignore files like cpulist */
continue;
snprintf(path, MAXPATHSIZE, "%s/%s/cache", node_dir, dir->d_name);
if (strlen(node_dir) + strlen(dir->d_name) + strlen("/cache") + 2 < MAXPATHSIZE) {
std::string path_str = std::string(node_dir) + "/" + dir->d_name + "/cache";
strncpy(path, path_str.c_str(), MAXPATHSIZE);
path[MAXPATHSIZE - 1] = '\0';
} else {
pr_err("Path is too long and was truncated.\n");
goto exit;
}
this_cpu->num_caches = num_subdirs(path, "index");
this_cpu->cache_prop = (HsaCacheProperties *)calloc(
this_cpu->num_caches, sizeof(HsaCacheProperties));