From d58118d1d3371c6f5d6cb8d53784f944f93e2643 Mon Sep 17 00:00:00 2001 From: Bruce Luckcuck Date: Tue, 3 Jul 2018 19:29:56 -0400 Subject: [PATCH] Fix null pointer reference for "smix reverse" The short syntax `smix reverse` is meant to print the table. When the logic was checking for parameters it was failing to deal with the null pointer when no parameters were present. Additionally the `smix reverse` was called at the end of a successful command to display the table so even though the command was succeeding it was crashing on the null pointer reference when trying to display the result. Also some stylistic cleanup --- src/main/interface/cli.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/interface/cli.c b/src/main/interface/cli.c index 8bdc5bb9e7..266e7aaf11 100644 --- a/src/main/interface/cli.c +++ b/src/main/interface/cli.c @@ -1891,8 +1891,7 @@ static void cliServoMix(char *cmdline) enum {SERVO = 0, INPUT, REVERSE, ARGS_COUNT}; char *ptr = strchr(cmdline, ' '); - len = strlen(ptr); - if (len == 0) { + if (ptr == NULL) { cliPrintf("s"); for (uint32_t inputSource = 0; inputSource < INPUT_SOURCE_COUNT; inputSource++) cliPrintf("\ti%d", inputSource); @@ -1900,8 +1899,9 @@ static void cliServoMix(char *cmdline) for (uint32_t servoIndex = 0; servoIndex < MAX_SUPPORTED_SERVOS; servoIndex++) { cliPrintf("%d", servoIndex); - for (uint32_t inputSource = 0; inputSource < INPUT_SOURCE_COUNT; inputSource++) + for (uint32_t inputSource = 0; inputSource < INPUT_SOURCE_COUNT; inputSource++) { cliPrintf("\t%s ", (servoParams(servoIndex)->reversedSources & (1 << inputSource)) ? "r" : "n"); + } cliPrintLinefeed(); } return; @@ -1922,12 +1922,15 @@ static void cliServoMix(char *cmdline) if (args[SERVO] >= 0 && args[SERVO] < MAX_SUPPORTED_SERVOS && args[INPUT] >= 0 && args[INPUT] < INPUT_SOURCE_COUNT && (*ptr == 'r' || *ptr == 'n')) { - if (*ptr == 'r') + if (*ptr == 'r') { servoParamsMutable(args[SERVO])->reversedSources |= 1 << args[INPUT]; - else + } else { servoParamsMutable(args[SERVO])->reversedSources &= ~(1 << args[INPUT]); - } else + } + } else { cliShowParseError(); + return; + } cliServoMix("reverse"); } else {