diff mbox series

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

Message ID 20180529061810.28003-4-stewart@linux.ibm.com
State Accepted
Headers show
Series Build fixes for GCC8 / Fedora 28 | expand

Commit Message

Stewart Smith May 29, 2018, 6:18 a.m. UTC
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@linux.ibm.com>
---
 hdata/spira.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff mbox series

Patch

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",