Add missing return in BleFingerprint::fingerprintServiceAdvertisements / Fix incorrect check in hextostr() (#1097)

* Add missing return in BleFingerprint::fingerprintServiceAdvertisements

This isn't _strictly_ required because setId() ignores "downgrades" to more
generic ID types (i.e. from ID_TYPE_FLORA to ID_TYPE_AD in this case) but
skips running unnecessary code and makes the code more readable.

* Fix incorrect check in hextostr()

This function decodes hex-encoded strings (e.g. "41" -> "A"). Previously we'd
check whether the output buffer's size is a multiple of two. This would
incorrectly reject valid uses of the function. Instead we should check the
input string's length.
This commit is contained in:
Gunnar Beutner 2023-11-09 23:46:53 +01:00 committed by GitHub
parent c70436e0a9
commit 4e440b29f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 1 deletions

View File

@ -236,6 +236,7 @@ void BleFingerprint::fingerprintServiceAdvertisements(NimBLEAdvertisedDevice *ad
} else if (uuid == miFloraUUID) { } else if (uuid == miFloraUUID) {
asRssi = BleFingerprintCollection::rxRefRssi + (haveTxPower ? txPower : FLORA_TX); asRssi = BleFingerprintCollection::rxRefRssi + (haveTxPower ? txPower : FLORA_TX);
setId("flora:" + getMac(), ID_TYPE_FLORA); setId("flora:" + getMac(), ID_TYPE_FLORA);
return;
} }
} }

View File

@ -107,7 +107,7 @@ uint8_t hextob(char ch)
bool hextostr(const String &hexStr, uint8_t* output, size_t len) bool hextostr(const String &hexStr, uint8_t* output, size_t len)
{ {
if (len & 1) return false; if (hexStr.length() & 1) return false;
if (hexStr.length() < len*2) return false; if (hexStr.length() < len*2) return false;
int k = 0; int k = 0;
for (size_t i = 0; i < len*2; i+=2) for (size_t i = 0; i < len*2; i+=2)