From cf3ed0e19f8621f03136d6ec1fbd9417519bbe6a Mon Sep 17 00:00:00 2001 From: wanghailiangx Date: Tue, 26 Jan 2021 04:12:49 -0500 Subject: [PATCH] test/app/stub: fix a null pointer passed as argument 'H' When val gets optarg and argument is 'H', a null pointer passed as argument 1, which is declared to never be null. So we adjust the order, judge 'H' first. Then './test/app/stub/stub -H' will display help info instead of 'Segmentation fault'. This patch fixed it. And case 'default' should return 1. Change-Id: I6ba9311eb5ac90266fdf33ab3424ab28fa64a78f Signed-off-by: wanghailiangx Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/6083 Tested-by: SPDK CI Jenkins Community-CI: Mellanox Build Bot Reviewed-by: Ben Walker Reviewed-by: Aleksey Marchuk --- test/app/stub/stub.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/app/stub/stub.c b/test/app/stub/stub.c index ff094515c..2fc18623d 100644 --- a/test/app/stub/stub.c +++ b/test/app/stub/stub.c @@ -158,9 +158,9 @@ main(int argc, char **argv) while ((ch = getopt(argc, argv, "i:m:n:p:s:H")) != -1) { if (ch == 'm') { opts.reactor_mask = optarg; - } else if (ch == '?') { + } else if (ch == '?' || ch == 'H') { usage(argv[0]); - exit(1); + exit(EXIT_SUCCESS); } else { val = spdk_strtol(optarg, 10); if (val < 0) { @@ -180,10 +180,9 @@ main(int argc, char **argv) case 's': opts.mem_size = val; break; - case 'H': default: usage(argv[0]); - exit(EXIT_SUCCESS); + exit(EXIT_FAILURE); } } }