diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2016-02-14 17:29:49 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2016-02-14 17:29:49 +0100 |
commit | ce07550c57172443c10a66957b50085e273d20b3 (patch) | |
tree | 8d0719a1fcf36fc7d25c20d5359f104f2f49b107 | |
parent | 8ded9e3d0bbc2d7cdc5b9f01b4fed9c8685caf82 (diff) | |
download | ble-toys-ce07550c57172443c10a66957b50085e273d20b3.tar.gz ble-toys-ce07550c57172443c10a66957b50085e273d20b3.tar.bz2 ble-toys-ce07550c57172443c10a66957b50085e273d20b3.tar.xz ble-toys-ce07550c57172443c10a66957b50085e273d20b3.zip |
o Fixing off-by-one error when reading device name.
-rw-r--r-- | apps/SoilMoisture.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/apps/SoilMoisture.cpp b/apps/SoilMoisture.cpp index 88f881a..13578f6 100644 --- a/apps/SoilMoisture.cpp +++ b/apps/SoilMoisture.cpp @@ -130,7 +130,11 @@ string SoilMoisture::getName(uint8_t sensor) { uint8_t bytes[bytesLeft]; buffer.copy(bytes, bytesLeft); - return string((char *) bytes, (unsigned long) bytesLeft); + if (bytesLeft == 0 || bytesLeft < (bytes[0] + 1)) { + throw runtime_error("Bad response from device. buffer size: " + to_string(bytesLeft) + ", buffer[0]=" + to_string((int)bytes[0])); + } + + return string((const char *)&bytes[1], bytes[0]); } bool SoilMoisture::hasTemperatureSensor() { |