[Skiboot] [PATCH 3/7] hdata/spira.c: fix iplparams feature name string handling

Stewart Smith stewart at linux.ibm.com
Tue May 29 16:18:06 AEST 2018


Fixes this gcc8 warning:

hdata/test/../spira.c: In function ‘add_iplparams_features’:
hdata/test/../spira.c:1209:38: error: argument to ‘sizeof’ in ‘strncpy’ call is the same expression as the source; did you mean to use the size of the destination? [-Werror=sizeof-pointer-memaccess]
   strncpy(name, feature->name, sizeof(feature->name));
                                      ^
Signed-off-by: Stewart Smith <stewart at linux.ibm.com>
---
 hdata/spira.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/hdata/spira.c b/hdata/spira.c
index 20879eea8dd2..b3894672efea 100644
--- a/hdata/spira.c
+++ b/hdata/spira.c
@@ -1206,7 +1206,9 @@ static void add_iplparams_features(const struct HDIF_common_hdr *iplp)
 		uint64_t flags;
 
 		/* the name field isn't necessarily null terminated */
-		strncpy(name, feature->name, sizeof(feature->name));
+		BUILD_ASSERT(sizeof(name) > sizeof(feature->name));
+		strncpy(name, feature->name, sizeof(name)-1);
+		name[sizeof(name)-1] = '\0';
 		flags = be64_to_cpu(feature->flags);
 
 		prlog(PR_DEBUG, "IPLPARAMS: FW feature %s = %016"PRIx64"\n",
-- 
2.17.0



More information about the Skiboot mailing list