From 43d8f67db2393c3400758c17fdc3dc6e2d201529 Mon Sep 17 00:00:00 2001 From: etracer65 Date: Sat, 3 Mar 2018 17:38:01 -0500 Subject: [PATCH] Fix diff support for array data types (#5366) Previously diff would only compare the first element of an array type. Changed valuePtrEqualsDefault() to make it array-aware and compare all elements to the defaults. --- src/main/interface/cli.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/main/interface/cli.c b/src/main/interface/cli.c index c38010e42..a4e8efe59 100644 --- a/src/main/interface/cli.c +++ b/src/main/interface/cli.c @@ -379,22 +379,30 @@ static void printValuePointer(const clivalue_t *var, const void *valuePointer, b } } -static bool valuePtrEqualsDefault(uint8_t type, const void *ptr, const void *ptrDefault) + +static bool valuePtrEqualsDefault(const clivalue_t *var, const void *ptr, const void *ptrDefault) { - bool result = false; - switch (type & VALUE_TYPE_MASK) { - case VAR_UINT8: - result = *(uint8_t *)ptr == *(uint8_t *)ptrDefault; - break; + bool result = true; + int elementCount = 1; - case VAR_INT8: - result = *(int8_t *)ptr == *(int8_t *)ptrDefault; - break; + if ((var->type & VALUE_MODE_MASK) == MODE_ARRAY) { + elementCount = var->config.array.length; + } + for (int i = 0; i < elementCount; i++) { + switch (var->type & VALUE_TYPE_MASK) { + case VAR_UINT8: + result = result && ((uint8_t *)ptr)[i] == ((uint8_t *)ptrDefault)[i]; + break; - case VAR_UINT16: - case VAR_INT16: - result = *(int16_t *)ptr == *(int16_t *)ptrDefault; - break; + case VAR_INT8: + result = result && ((int8_t *)ptr)[i] == ((int8_t *)ptrDefault)[i]; + break; + + case VAR_UINT16: + case VAR_INT16: + result = result && ((int16_t *)ptr)[i] == ((int16_t *)ptrDefault)[i]; + break; + } } return result; @@ -438,7 +446,7 @@ static void dumpPgValue(const clivalue_t *value, uint8_t dumpMask) const char *format = "set %s = "; const char *defaultFormat = "#set %s = "; const int valueOffset = getValueOffset(value); - const bool equalsDefault = valuePtrEqualsDefault(value->type, pg->copy + valueOffset, pg->address + valueOffset); + const bool equalsDefault = valuePtrEqualsDefault(value, pg->copy + valueOffset, pg->address + valueOffset); if (((dumpMask & DO_DIFF) == 0) || !equalsDefault) { if (dumpMask & SHOW_DEFAULTS && !equalsDefault) {