From 78040c772b5f63f432271a4576065a2efd4bf175 Mon Sep 17 00:00:00 2001 From: Nicholas Piggin Date: Wed, 8 May 2019 16:17:49 +1000 Subject: [PATCH] core/pci: pci_slot_add_loc use null-terminated strings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use null-terminated strings consistently, making the maximum string length in all cases the same, and avoiding dt_add_property_nstr. This avoids the following warning that appears after adding more checking to string ops: core/pci-slot.c: In function ‘pci_slot_add_loc’: skiboot/libc/include/string.h:19:17: warning: ‘__builtin_strncpy’ specified bound 80 equals destination size [-Wstringop-truncation] #define strncpy __builtin_strncpy core/pci-slot.c:244:3: note: in expansion of macro ‘strncpy’ strncpy(loc_code, label, sizeof(loc_code)); ^~~~~~~ Signed-off-by: Nicholas Piggin Reviewed-by: Vasant Hegde Signed-off-by: Stewart Smith --- core/pci-slot.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/pci-slot.c b/core/pci-slot.c index 497d0a47f426..d8c80241f8c3 100644 --- a/core/pci-slot.c +++ b/core/pci-slot.c @@ -241,10 +241,10 @@ void pci_slot_add_loc(struct pci_slot *slot, snprintf(loc_code, sizeof(loc_code), "%s-%s", phb->base_loc_code, label); } else { - strncpy(loc_code, label, sizeof(loc_code)); + strncpy(loc_code, label, sizeof(loc_code) - 1); + loc_code[LOC_CODE_SIZE - 1] = '\0'; } dt_add_property_string(np, "ibm,slot-label", label); - dt_add_property_nstr(np, "ibm,slot-location-code", loc_code, - sizeof(loc_code)); + dt_add_property_string(np, "ibm,slot-location-code", loc_code); }