1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-14 20:10:18 +03:00

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
This commit is contained in:
Bruce Luckcuck 2018-07-03 19:29:56 -04:00
parent b44784d962
commit d58118d1d3

View file

@ -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 {