examples/ioat: Improve error check of input parsing by spdk_strtol

Change-Id: Ia71c7047c0611a2b66126e57e36427ed791d3a43
Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/c/441628
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: wuzhouhui <wuzhouhui@kingsoft.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
This commit is contained in:
Shuhei Matsumoto 2019-01-23 09:02:56 +09:00 committed by Jim Harris
parent 404c5a3fd0
commit 47fadb7f9b
2 changed files with 11 additions and 10 deletions

View File

@ -264,16 +264,16 @@ parse_args(int argc, char **argv)
while ((op = getopt(argc, argv, "c:hn:o:q:t:v")) != -1) {
switch (op) {
case 'o':
g_user_config.xfer_size_bytes = atoi(optarg);
g_user_config.xfer_size_bytes = spdk_strtol(optarg, 10);
break;
case 'n':
g_user_config.ioat_chan_num = atoi(optarg);
g_user_config.ioat_chan_num = spdk_strtol(optarg, 10);
break;
case 'q':
g_user_config.queue_depth = atoi(optarg);
g_user_config.queue_depth = spdk_strtol(optarg, 10);
break;
case 't':
g_user_config.time_in_sec = atoi(optarg);
g_user_config.time_in_sec = spdk_strtol(optarg, 10);
break;
case 'c':
g_user_config.core_mask = optarg;
@ -289,9 +289,9 @@ parse_args(int argc, char **argv)
return 1;
}
}
if (!g_user_config.xfer_size_bytes || !g_user_config.queue_depth ||
!g_user_config.time_in_sec || !g_user_config.core_mask ||
!g_user_config.ioat_chan_num) {
if (g_user_config.xfer_size_bytes <= 0 || g_user_config.queue_depth <= 0 ||
g_user_config.time_in_sec <= 0 || !g_user_config.core_mask ||
g_user_config.ioat_chan_num <= 0) {
usage(argv[0]);
return 1;
}

View File

@ -256,13 +256,13 @@ parse_args(int argc, char **argv)
while ((op = getopt(argc, argv, "c:ht:q:")) != -1) {
switch (op) {
case 't':
g_user_config.time_in_sec = atoi(optarg);
g_user_config.time_in_sec = spdk_strtol(optarg, 10);
break;
case 'c':
g_user_config.core_mask = optarg;
break;
case 'q':
g_user_config.queue_depth = atoi(optarg);
g_user_config.queue_depth = spdk_strtol(optarg, 10);
break;
case 'h':
usage(argv[0]);
@ -272,7 +272,8 @@ parse_args(int argc, char **argv)
return 1;
}
}
if (!g_user_config.time_in_sec || !g_user_config.core_mask || !g_user_config.queue_depth) {
if (g_user_config.time_in_sec <= 0 || !g_user_config.core_mask ||
g_user_config.queue_depth <= 0) {
usage(argv[0]);
return 1;
}