From fb551a44af8433f50ebe76fb8a71b823745cfa26 Mon Sep 17 00:00:00 2001 From: Felix Kuehling Date: Mon, 25 Jun 2018 14:25:29 -0400 Subject: [PATCH] Fix compiler warning on Fedora 28 Avoid warnings of the type error: 'strncpy' specified bound 64 equals destination size With the destination being 0-initialized, subtracting 1 from the destination buffer size will ensure that the destination will be a 0-terminated string, even when it's truncated. Change-Id: I7c3a90482065ce4d020db215e3e41348de51a083 Signed-off-by: Felix Kuehling --- src/topology.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/topology.c b/src/topology.c index c409bef14e..32fa642b1d 100644 --- a/src/topology.c +++ b/src/topology.c @@ -669,7 +669,7 @@ static HSAKMT_STATUS topology_get_cpu_model_name(HsaNodeProperties *props, if (props->CComputeIdLo == apic_id) { /* Retrieve the CAL name of CPU node */ if (!is_apu) - strncpy((char *)props->AMDName, cpu_model_name, sizeof(props->AMDName)); + strncpy((char *)props->AMDName, cpu_model_name, sizeof(props->AMDName)-1); /* Convert from UTF8 to UTF16 */ for (i = 0; cpu_model_name[i] != '\0' && i < HSA_PUBLIC_NAME_SIZE - 1; i++) props->MarketingName[i] = cpu_model_name[i]; @@ -867,7 +867,7 @@ HSAKMT_STATUS topology_sysfs_get_node_props(uint32_t node_id, } /* Retrieve the CAL name of the node */ - strncpy((char *)props->AMDName, hsa_gfxip->amd_name, sizeof(props->AMDName)); + strncpy((char *)props->AMDName, hsa_gfxip->amd_name, sizeof(props->AMDName)-1); if (props->NumCPUCores) { /* Is APU node */ ret = topology_get_cpu_model_name(props, true);