fix constant comparison (#162)

* fix constant comparison

* .
This commit is contained in:
croghostrider 2021-12-29 17:20:46 +01:00 committed by GitHub
parent 12d0ea1ad8
commit bf70e162f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 11 deletions

View File

@ -82,7 +82,7 @@ int FdskCalculator::toBase32(uint8_t* in, long length, uint8_t*& out, bool usePa
int next = 1; int next = 1;
int bitsLeft = 8; int bitsLeft = 8;
while (count < bufSize && (bitsLeft > 0 || next < length)) while (bitsLeft > 0 || next < length)
{ {
if (bitsLeft < 5) if (bitsLeft < 5)
{ {

View File

@ -82,7 +82,7 @@ int FdskCalculator::toBase32(uint8_t* in, long length, uint8_t*& out, bool usePa
int next = 1; int next = 1;
int bitsLeft = 8; int bitsLeft = 8;
while (count < bufSize && (bitsLeft > 0 || next < length)) while (bitsLeft > 0 || next < length)
{ {
if (bitsLeft < 5) if (bitsLeft < 5)
{ {

View File

@ -25,7 +25,7 @@ uint16_t AssociationTableObject::entryCount()
uint16_t AssociationTableObject::getTSAP(uint16_t idx) uint16_t AssociationTableObject::getTSAP(uint16_t idx)
{ {
if (idx < 0 || idx >= entryCount()) if (idx >= entryCount())
return 0; return 0;
return ntohs(_tableData[2 * idx + 1]); return ntohs(_tableData[2 * idx + 1]);
@ -33,7 +33,7 @@ uint16_t AssociationTableObject::getTSAP(uint16_t idx)
uint16_t AssociationTableObject::getASAP(uint16_t idx) uint16_t AssociationTableObject::getASAP(uint16_t idx)
{ {
if (idx < 0 || idx >= entryCount()) if (idx >= entryCount())
return 0; return 0;
return ntohs(_tableData[2 * idx + 2]); return ntohs(_tableData[2 * idx + 2]);

View File

@ -483,7 +483,7 @@ bool BauSystemB::restartRequest(uint16_t asap, const SecurityControl secCtrl)
void BauSystemB::connectConfirm(uint16_t tsap) void BauSystemB::connectConfirm(uint16_t tsap)
{ {
if (_restartState == Connecting && tsap >= 0) if (_restartState == Connecting)
{ {
/* restart connection is confirmed, go to the next state */ /* restart connection is confirmed, go to the next state */
_restartState = Connected; _restartState = Connected;

View File

@ -797,8 +797,6 @@ int busValueToRGB(const uint8_t* payload, size_t payload_length, const Dpt& data
{ {
ASSERT_PAYLOAD(3); ASSERT_PAYLOAD(3);
uint32_t rgb = unsigned16FromPayload(payload, 0) * 256 + unsigned8FromPayload(payload, 2); uint32_t rgb = unsigned16FromPayload(payload, 0) * 256 + unsigned8FromPayload(payload, 2);
if (rgb > 16777215)
return false;
value = rgb; value = rgb;
return true; return true;
} }
@ -886,7 +884,7 @@ int valueToBusValueStepControl(const KNXValue& value, uint8_t* payload, size_t p
int valueToBusValueCharacter(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype) int valueToBusValueCharacter(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
{ {
if ((uint64_t)value < INT64_C(0) || (uint64_t)value > INT64_C(255) || (datatype.subGroup == 1 && (uint64_t)value > INT64_C(127))) if ((uint64_t)value > INT64_C(255) || (datatype.subGroup == 1 && (uint64_t)value > INT64_C(127)))
return false; return false;
unsigned8ToPayload(payload, payload_length, 0, (uint64_t)value, 0xFF); unsigned8ToPayload(payload, payload_length, 0, (uint64_t)value, 0xFF);
return true; return true;
@ -1153,7 +1151,7 @@ int valueToBusValueAccess(const KNXValue& value, uint8_t* payload, size_t payloa
break; break;
case 5: case 5:
{ {
if ((uint64_t)value < INT64_C(0) || (uint64_t)value > INT64_C(15)) if ((uint64_t)value > INT64_C(15))
return false; return false;
bcdToPayload(payload, payload_length, 7, (uint64_t)value); bcdToPayload(payload, payload_length, 7, (uint64_t)value);
break; break;
@ -1444,7 +1442,7 @@ int valueToBusValueScaling(const KNXValue& value, uint8_t* payload, size_t paylo
{ {
uint32_t duration = value; uint32_t duration = value;
if (duration < INT64_C(0) || duration > INT64_C(65535)) if (duration > INT64_C(65535))
return false; return false;
ENSURE_PAYLOAD(3); ENSURE_PAYLOAD(3);
@ -1471,7 +1469,7 @@ int valueToBusValueTariff(const KNXValue& value, uint8_t* payload, size_t payloa
{ {
uint32_t duration = value; uint32_t duration = value;
if (duration < INT64_C(0) || duration > INT64_C(65535)) if (duration > INT64_C(65535))
return false; return false;
ENSURE_PAYLOAD(3); ENSURE_PAYLOAD(3);