Commit f56de7b8 authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Darek Stojaczyk
Browse files

test/app: Improve error check of input parsing by spdk_strtol



Change-Id: I7da74760a7cd099c512b966c87e05a4a7084b360
Signed-off-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/c/441644


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarDarek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: default avatarwuzhouhui <wuzhouhui@kingsoft.com>
parent b252a13a
Loading
Loading
Loading
Loading
+29 −18
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@

#include "spdk/event.h"
#include "spdk/nvme.h"
#include "spdk/string.h"

static char g_path[256];

@@ -100,6 +101,7 @@ main(int argc, char **argv)
{
	int ch;
	struct spdk_app_opts opts = {};
	long int val;

	/* default value in opts structure */
	spdk_app_opts_init(&opts);
@@ -108,21 +110,29 @@ main(int argc, char **argv)
	opts.rpc_addr = NULL;

	while ((ch = getopt(argc, argv, "i:m:n:p:s:H")) != -1) {
		if (ch == 'm') {
			opts.reactor_mask = optarg;
		} else if (ch == '?') {
			usage(argv[0]);
			exit(1);
		} else {
			val = spdk_strtol(optarg, 10);
			if (val < 0) {
				fprintf(stderr, "Converting a string to integer failed\n");
				exit(1);
			}
			switch (ch) {
			case 'i':
			opts.shm_id = atoi(optarg);
			break;
		case 'm':
			opts.reactor_mask = optarg;
				opts.shm_id = val;
				break;
			case 'n':
			opts.mem_channel = atoi(optarg);
				opts.mem_channel = val;
				break;
			case 'p':
			opts.master_core = atoi(optarg);
				opts.master_core = val;
				break;
			case 's':
			opts.mem_size = atoi(optarg);
				opts.mem_size = val;
				break;
			case 'H':
			default:
@@ -130,6 +140,7 @@ main(int argc, char **argv)
				exit(EXIT_SUCCESS);
			}
		}
	}

	if (opts.shm_id < 0) {
		fprintf(stderr, "%s: -i shared memory ID must be specified\n", argv[0]);