aboutsummaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/SoilMoisture.cpp6
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() {