From be1641434b5b6a74418e185cfa84b1dad63c8207 Mon Sep 17 00:00:00 2001 From: Christian Stauffer <37304790+ChrIgiSta@users.noreply.github.com> Date: Wed, 26 Sep 2018 19:23:44 +0200 Subject: [PATCH] [cli] fix NULL pointer udp example cli, when udp called without args (#3101) --- src/cli/cli_udp_example.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/cli/cli_udp_example.cpp b/src/cli/cli_udp_example.cpp index 9a1e7bcaf..cd32c272a 100644 --- a/src/cli/cli_udp_example.cpp +++ b/src/cli/cli_udp_example.cpp @@ -180,15 +180,22 @@ otError UdpExample::Process(int argc, char *argv[]) { otError error = OT_ERROR_PARSE; - for (size_t i = 0; i < OT_ARRAY_LENGTH(sCommands); i++) + if (argc < 1) { - if (strcmp(argv[0], sCommands[i].mName) == 0) + ProcessHelp(0, NULL); + error = OT_ERROR_INVALID_ARGS; + } + else + { + for (size_t i = 0; i < OT_ARRAY_LENGTH(sCommands); i++) { - error = (this->*sCommands[i].mCommand)(argc - 1, argv + 1); - break; + if (strcmp(argv[0], sCommands[i].mName) == 0) + { + error = (this->*sCommands[i].mCommand)(argc - 1, argv + 1); + break; + } } } - return error; }