mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-15 20:35:33 +03:00
Fix CLI bug where incorrect variables would be set when similarly named
variables are used. Previously the following was broken: set option = 1 set option_extra = 2 Instead of setting 'option_extra' to two 'option' was set to 2 if 'option' appeared before 'option_extra' in the list of settings.
This commit is contained in:
parent
e867af8c4b
commit
f8bdc79a9f
1 changed files with 8 additions and 1 deletions
|
@ -888,13 +888,20 @@ static void cliSet(char *cmdline)
|
||||||
}
|
}
|
||||||
} else if ((eqptr = strstr(cmdline, "=")) != NULL) {
|
} else if ((eqptr = strstr(cmdline, "=")) != NULL) {
|
||||||
// has equal, set var
|
// has equal, set var
|
||||||
|
char *lastNonSpaceCharacter = eqptr;
|
||||||
|
while (*(lastNonSpaceCharacter - 1) == ' ') {
|
||||||
|
lastNonSpaceCharacter--;
|
||||||
|
}
|
||||||
|
uint8_t variableNameLength = lastNonSpaceCharacter - cmdline;
|
||||||
|
|
||||||
eqptr++;
|
eqptr++;
|
||||||
len--;
|
len--;
|
||||||
value = atoi(eqptr);
|
value = atoi(eqptr);
|
||||||
valuef = fastA2F(eqptr);
|
valuef = fastA2F(eqptr);
|
||||||
for (i = 0; i < VALUE_COUNT; i++) {
|
for (i = 0; i < VALUE_COUNT; i++) {
|
||||||
val = &valueTable[i];
|
val = &valueTable[i];
|
||||||
if (strncasecmp(cmdline, valueTable[i].name, strlen(valueTable[i].name)) == 0) {
|
// ensure exact match when setting to prevent setting variables with shorter names
|
||||||
|
if (strncasecmp(cmdline, valueTable[i].name, strlen(valueTable[i].name)) == 0 && variableNameLength == strlen(valueTable[i].name)) {
|
||||||
if (valuef >= valueTable[i].min && valuef <= valueTable[i].max) { // here we compare the float value since... it should work, RIGHT?
|
if (valuef >= valueTable[i].min && valuef <= valueTable[i].max) { // here we compare the float value since... it should work, RIGHT?
|
||||||
int_float_value_t tmp;
|
int_float_value_t tmp;
|
||||||
if (valueTable[i].type == VAR_FLOAT)
|
if (valueTable[i].type == VAR_FLOAT)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue