From 404c5a3fd019190d39380bff2175eb52ba551ae5 Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Wed, 23 Jan 2019 08:46:11 +0900 Subject: [PATCH] blobcli: Improve error check of input parsing by spdk_strtol It looks that each call of atoi expects atoi returns negative for any error. spdk_strtol will satisfy this requirement. Change-Id: Ic21817499ed280ef4b26809ab311f337c2636470 Signed-off-by: Shuhei Matsumoto Reviewed-on: https://review.gerrithub.io/c/441627 Tested-by: SPDK CI Jenkins Chandler-Test-Pool: SPDK Automated Test System Reviewed-by: Darek Stojaczyk Reviewed-by: wuzhouhui Reviewed-by: Ben Walker Reviewed-by: Changpeng Liu --- examples/blob/cli/blobcli.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/blob/cli/blobcli.c b/examples/blob/cli/blobcli.c index 342475645..bb01e5a28 100644 --- a/examples/blob/cli/blobcli.c +++ b/examples/blob/cli/blobcli.c @@ -1081,7 +1081,7 @@ cmd_parser(int argc, char **argv, struct cli_context_t *cli_context) cmd_chosen++; cli_context->action = CLI_FILL; cli_context->blobid = atoll(optarg); - cli_context->fill_value = atoi(argv[optind]); + cli_context->fill_value = spdk_strtol(argv[optind], 10); } else { usage(cli_context, "ERROR: missing parameter.\n"); } @@ -1141,7 +1141,7 @@ cmd_parser(int argc, char **argv, struct cli_context_t *cli_context) } break; case 'n': - cli_context->num_clusters = atoi(optarg); + cli_context->num_clusters = spdk_strtol(optarg, 10); if (cli_context->num_clusters > 0) { cmd_chosen++; cli_context->action = CLI_CREATE_BLOB; @@ -1251,7 +1251,7 @@ line_parser(struct cli_context_t *cli_context) cli_context->argv[cli_context->argc] = strdup(tok); if (tok[0] == '$' && tok[1] == 'B') { tok += 2; - blob_num = atoi(tok); + blob_num = spdk_strtol(tok, 10); if (blob_num >= 0 && blob_num < MAX_SCRIPT_BLOBS) { cli_context->argv[cli_context->argc] = realloc(cli_context->argv[cli_context->argc], BUFSIZE);