nvme: simplify spdk_nvme_transport_id_populate_trstring
Note that this also works around a false positive in gcc-11 of type -Wstringop-overread. Fixes issue #2391. Signed-off-by: Jim Harris <james.r.harris@intel.com> Change-Id: Ib5301b9ef9fa3ead2a1a2318655533a8cfba03fe Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11709 Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com> Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Dong Yi <dongx.yi@intel.com> Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com> Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
This commit is contained in:
parent
adde7ea533
commit
12d522515f
@ -1068,27 +1068,24 @@ spdk_nvme_trid_populate_transport(struct spdk_nvme_transport_id *trid,
|
||||
int
|
||||
spdk_nvme_transport_id_populate_trstring(struct spdk_nvme_transport_id *trid, const char *trstring)
|
||||
{
|
||||
int len, i, rc;
|
||||
int i = 0;
|
||||
|
||||
if (trstring == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
len = strnlen(trstring, SPDK_NVMF_TRSTRING_MAX_LEN);
|
||||
if (len == SPDK_NVMF_TRSTRING_MAX_LEN) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
rc = snprintf(trid->trstring, SPDK_NVMF_TRSTRING_MAX_LEN, "%s", trstring);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
/* Note: gcc-11 has some false positive -Wstringop-overread warnings with LTO builds if we
|
||||
* use strnlen here. So do the trstring copy manually instead. See GitHub issue #2391.
|
||||
*/
|
||||
|
||||
/* cast official trstring to uppercase version of input. */
|
||||
for (i = 0; i < len; i++) {
|
||||
trid->trstring[i] = toupper(trid->trstring[i]);
|
||||
while (i < SPDK_NVMF_TRSTRING_MAX_LEN && trstring[i] != 0) {
|
||||
trid->trstring[i] = toupper(trstring[i]);
|
||||
i++;
|
||||
}
|
||||
|
||||
if (trstring[i] != 0) {
|
||||
return -EINVAL;
|
||||
} else {
|
||||
trid->trstring[i] = 0;
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
|
Loading…
Reference in New Issue
Block a user