Skip to content

Commit dafb0b2

Browse files
mdavidsaverralphlange
authored andcommitted
json: fix string comparison
1 parent e7a3efb commit dafb0b2

File tree

1 file changed

+10
-33
lines changed

1 file changed

+10
-33
lines changed

caPutLogApp/caPutJsonLogTask.cpp

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -812,47 +812,24 @@ void CaPutJsonLogTask::calculateMax(VALUE *pres, const VALUE *pa, const VALUE *p
812812
memset(pres, 0, sizeof(*pres));
813813
}
814814

815-
#define SINGLE_TYPE_COMPARE(_t, _s) \
816-
if (pLogData->is_array) \
817-
return memcmp(pa->a_##_t, pb->a_##_t, size * _s) == 0; \
818-
return pa->v_##_t == pb->v_##_t;
819-
820815
bool CaPutJsonLogTask::compareValues(const LOGDATA *pLogData) {
821816
const VALUE *pa = &pLogData->old_value;
822817
const VALUE *pb = &pLogData->new_value.value;
823-
const int size = pLogData->old_log_size;
824818

825819
if (pLogData->is_array && pLogData->old_log_size != pLogData->new_log_size)
826820
return false;
827821

828-
switch (pLogData->type)
829-
{
830-
case DBR_CHAR:
831-
SINGLE_TYPE_COMPARE(int8, sizeof(epicsInt8));
832-
case DBR_UCHAR:
833-
SINGLE_TYPE_COMPARE(uint8, sizeof(epicsUInt8));
834-
case DBR_SHORT:
835-
SINGLE_TYPE_COMPARE(int16, sizeof(epicsInt16));
836-
case DBR_USHORT:
837-
case DBR_ENUM:
838-
SINGLE_TYPE_COMPARE(uint16, sizeof(epicsUInt16));
839-
case DBR_LONG:
840-
SINGLE_TYPE_COMPARE(int32, sizeof(epicsInt32));
841-
case DBR_ULONG:
842-
SINGLE_TYPE_COMPARE(uint32, sizeof(epicsUInt32));
843-
case DBR_INT64:
844-
SINGLE_TYPE_COMPARE(int64, sizeof(epicsInt64));
845-
case DBR_UINT64:
846-
SINGLE_TYPE_COMPARE(uint64, sizeof(epicsUInt64));
847-
case DBR_FLOAT:
848-
SINGLE_TYPE_COMPARE(float, sizeof(epicsFloat32));
849-
case DBR_DOUBLE:
850-
SINGLE_TYPE_COMPARE(double, sizeof(epicsFloat64));
851-
case DBR_STRING:
852-
SINGLE_TYPE_COMPARE(string, MAX_STRING_SIZE);
853-
default:
854-
return 0;
822+
size_t size = pLogData->is_array ? pLogData->old_log_size : 1;
823+
if(pLogData->type==DBR_STRING) {
824+
for(size_t i=0; i<size; i++) {
825+
if(strncmp(pa->a_string[i], pb->a_string[i], MAX_STRING_SIZE)!=0) {
826+
return 0;
827+
}
828+
}
829+
} else {
830+
return memcmp(pa, pb, size*dbValueSize(pLogData->type))==0;
855831
}
832+
return 1;
856833
}
857834

858835
int CaPutJsonLogTask::fieldVal2Str(char *pbuf, size_t buflen, const VALUE *pval, short type, int index)

0 commit comments

Comments
 (0)