test/cuse: fix ns_dev format truncation
gcc 12 assumes that nsid might take value of UINT32_MAX, which when represented as a string does not fit in ns_dev. This is fixed by accomodating the UINT32_MAX string representation and the 'n' character. Following error was shown before this patch: cuse.c: In function ‘verify_devices’: cuse.c:133:42: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=] 133 | snprintf(ns_dev, sizeof(ns_dev), "%sn%" PRIu32, ctrlr_dev, nsid); | ^~~~~~ In file included from /home/tzawadzk/spdk/include/spdk/stdinc.h:23, from /home/tzawadzk/spdk/test/spdk_cunit.h:9, from cuse.c:7: /usr/include/inttypes.h:104:27: note: format string is defined here 104 | # define PRIu32 "u" | ^ cuse.c:133:9: note: ‘snprintf’ output between 3 and 267 bytes into a destination of size 266 133 | snprintf(ns_dev, sizeof(ns_dev), "%sn%" PRIu32, ctrlr_dev, nsid); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Change-Id: I14e058edc780d33abdd5eb6ce5ab47ac5d18f10a Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/13412 Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Konrad Sztyber <konrad.sztyber@intel.com> Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
This commit is contained in:
parent
8c532ae032
commit
98292d1eee
@ -106,7 +106,8 @@ verify_devices(struct spdk_nvme_ctrlr *ctrlr)
|
|||||||
{
|
{
|
||||||
char ctrlr_name[256];
|
char ctrlr_name[256];
|
||||||
size_t ctrlr_name_size;
|
size_t ctrlr_name_size;
|
||||||
char ctrlr_dev[256], ns_dev[256 + 10];
|
char ctrlr_dev[256];
|
||||||
|
char ns_dev[256 + 1 + 10]; /* sizeof ctrl_dev + 'n' + string size of UINT32_MAX */
|
||||||
uint32_t nsid, num_ns;
|
uint32_t nsid, num_ns;
|
||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user