nvmf/tcp: Eliminate atoi use
Use spdk_strtol instead, which does better error detection. Change-Id: I14236a0b3e42f39a65d67149dd91d791be9f55f1 Signed-off-by: Ben Walker <benjamin.walker@intel.com> Reviewed-on: https://review.gerrithub.io/c/441983 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-by: wuzhouhui <wuzhouhui@kingsoft.com> Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
This commit is contained in:
parent
f56de7b8cf
commit
e8207e9d5d
@ -44,6 +44,7 @@
|
||||
#include "spdk/crc32.h"
|
||||
#include "spdk/endian.h"
|
||||
#include "spdk/assert.h"
|
||||
#include "spdk/string.h"
|
||||
#include "spdk/thread.h"
|
||||
#include "spdk/trace.h"
|
||||
#include "spdk/util.h"
|
||||
@ -1640,6 +1641,7 @@ nvme_tcp_qpair_connect(struct nvme_tcp_qpair *tqpair)
|
||||
int rc;
|
||||
struct spdk_nvme_ctrlr *ctrlr;
|
||||
int family;
|
||||
long int port;
|
||||
|
||||
ctrlr = tqpair->qpair.ctrlr;
|
||||
|
||||
@ -1675,10 +1677,16 @@ nvme_tcp_qpair_connect(struct nvme_tcp_qpair *tqpair)
|
||||
}
|
||||
}
|
||||
|
||||
tqpair->sock = spdk_sock_connect(ctrlr->trid.traddr, atoi(ctrlr->trid.trsvcid));
|
||||
port = spdk_strtol(ctrlr->trid.trsvcid, 10);
|
||||
if (port <= 0 || port >= INT_MAX) {
|
||||
SPDK_ERRLOG("Invalid port: %s\n", ctrlr->trid.trsvcid);
|
||||
return -1;
|
||||
}
|
||||
|
||||
tqpair->sock = spdk_sock_connect(ctrlr->trid.traddr, port);
|
||||
if (!tqpair->sock) {
|
||||
SPDK_ERRLOG("sock connection error of tqpair=%p with addr=%s, port=%d\n",
|
||||
tqpair, ctrlr->trid.traddr, atoi(ctrlr->trid.trsvcid));
|
||||
SPDK_ERRLOG("sock connection error of tqpair=%p with addr=%s, port=%ld\n",
|
||||
tqpair, ctrlr->trid.traddr, port);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user