Skip to content

Commit

Permalink
core/pci: pci_slot_add_loc use null-terminated strings
Browse files Browse the repository at this point in the history
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 <npiggin@gmail.com>
Reviewed-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
  • Loading branch information
npiggin authored and stewartsmith committed May 15, 2019
1 parent a8343d5 commit 78040c7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions core/pci-slot.c
Expand Up @@ -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);
}

0 comments on commit 78040c7

Please sign in to comment.