Index: sources/model/hd/alarm/MAlarmMapping.cpp =================================================================== diff -u -r5d7df7a4ffd8c3a6302a1de536ca3ee83a0b3f6f -rc0a4c9b399f02fb112de89f6cc74077b4023d8cc --- sources/model/hd/alarm/MAlarmMapping.cpp (.../MAlarmMapping.cpp) (revision 5d7df7a4ffd8c3a6302a1de536ca3ee83a0b3f6f) +++ sources/model/hd/alarm/MAlarmMapping.cpp (.../MAlarmMapping.cpp) (revision c0a4c9b399f02fb112de89f6cc74077b4023d8cc) @@ -7,7 +7,7 @@ * * \file MAlarmMapping.cpp * \author (last) Behrouz NematiPour - * \date (last) 28-Jan-2024 + * \date (last) 03-Feb-2024 * \author (original) Behrouz NematiPour * \date (original) 03-May-2021 * Index: sources/utility/types.h =================================================================== diff -u -r2ef03b2ce51b4dc507f66e9671953a8e0824bde9 -rc0a4c9b399f02fb112de89f6cc74077b4023d8cc --- sources/utility/types.h (.../types.h) (revision 2ef03b2ce51b4dc507f66e9671953a8e0824bde9) +++ sources/utility/types.h (.../types.h) (revision c0a4c9b399f02fb112de89f6cc74077b4023d8cc) @@ -152,22 +152,22 @@ template < typename T > bool Types::getValue(const QByteArray &vData, int &vStartIndex, T &vValue, QString vValueName) { - int end = vStartIndex + sizeof(T); + int size = sizeof(T); + int end = vStartIndex + size; if (vData.length() < end) { LOG_DEBUG(QString("Not enough data from position %1 to the length of %2 to get data of type '%3' in buffer %4 %5") - .arg(vStartIndex) - .arg(sizeof(T)) - .arg(typeid(T).name()) - .arg(Format::toHexString(vData)) - .arg(vValueName.isEmpty() ? "" : QString("for value %1").arg(vValueName)) - ); + .arg(vStartIndex) + .arg(size) + .arg(typeid(T).name()) + .arg(Format::toHexString(vData)) + .arg(vValueName.isEmpty() ? "" : QString("for value %1").arg(vValueName)) + ); return false; } int i = 0; - while (vStartIndex < end) { - vValue.bytes[i] = vData[vStartIndex]; + while (i < size) { + vValue.bytes[i] = vData[vStartIndex + i]; i++; - vStartIndex++; } return true; } Index: unittests/tst_utilities.cpp =================================================================== diff -u -r2ef03b2ce51b4dc507f66e9671953a8e0824bde9 -rc0a4c9b399f02fb112de89f6cc74077b4023d8cc --- unittests/tst_utilities.cpp (.../tst_utilities.cpp) (revision 2ef03b2ce51b4dc507f66e9671953a8e0824bde9) +++ unittests/tst_utilities.cpp (.../tst_utilities.cpp) (revision c0a4c9b399f02fb112de89f6cc74077b4023d8cc) @@ -235,7 +235,7 @@ QCOMPARE(mActual, mExpected); } -void tst_utilities::tst_getValue_len() +void tst_utilities::tst_getValue_len_log() { Types::S32 vFlowSetPoint; int index = 0; @@ -244,6 +244,55 @@ QVERIFY( ! Types::getValue<>( data, index, vFlowSetPoint ) ); } +void tst_utilities::tst_getValue_len_lt() +{ + bool ok = true; + int index = 0; + Types::S32 vFlowSetPoint; + QByteArray data; + data += 0x01; + data += 0x02; + data += 0x03; + data += 0x04; + data += 0x05; + ok = GetValue( data, index, vFlowSetPoint ) && ok; + QVERIFY( ok ); +} + +void tst_utilities::tst_getValue_len_eq() +{ + bool ok = true; + int index = 0; + Types::S32 vP1; + Types::U08 vP2; + QByteArray data; + data += 0x01; + data += 0x02; + data += 0x03; + data += 0x04; + data += 0x05; + ok = GetValue( data, index, vP1 ) && ok; + ok = GetValue( data, index, vP2 ) && ok; + QVERIFY( ok ); +} + +void tst_utilities::tst_getValue_len_gt() +{ + bool ok = true; + int index = 0; + Types::S32 vP1; + Types::U16 vP2; + QByteArray data; + data += 0x01; + data += 0x02; + data += 0x03; + data += 0x04; + data += 0x05; + ok = GetValue( data, index, vP1 ) && ok; + ok = GetValue( data, index, vP2 ) && ok; + QVERIFY( ok ); +} + void tst_utilities::tst_safeIncrement_StepZero() { uchar c = 0; Index: unittests/tst_utilities.h =================================================================== diff -u -r2ef03b2ce51b4dc507f66e9671953a8e0824bde9 -rc0a4c9b399f02fb112de89f6cc74077b4023d8cc --- unittests/tst_utilities.h (.../tst_utilities.h) (revision 2ef03b2ce51b4dc507f66e9671953a8e0824bde9) +++ unittests/tst_utilities.h (.../tst_utilities.h) (revision c0a4c9b399f02fb112de89f6cc74077b4023d8cc) @@ -25,7 +25,10 @@ explicit tst_utilities(QObject *parent = nullptr); private slots: - void tst_getValue_len(); + void tst_getValue_len_log(); + void tst_getValue_len_lt(); + void tst_getValue_len_eq(); + void tst_getValue_len_gt(); void tst_floatCompare_noMatch(); void tst_floatCompare_isMatch(); void tst_getbits_NoError();