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.
This commit is contained in:
parent
5d3c3b766b
commit
43d8f67db2
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue