Skip to content

Commit e39e8ab

Browse files
committed
Only updates the supplied deviceAddress if a valid index is specified
1 parent 65112b5 commit e39e8ab

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

DallasTemperature.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,19 +152,19 @@ bool DallasTemperature::validAddress(const uint8_t* deviceAddress) {
152152
// finds an address at a given index on the bus
153153
// returns true if the device was found
154154
bool DallasTemperature::getAddress(uint8_t* deviceAddress, uint8_t index) {
155+
if (index < devices) {
156+
uint8_t depth = 0;
155157

156-
uint8_t depth = 0;
158+
_wire->reset_search();
157159

158-
_wire->reset_search();
159-
160-
while (depth <= index && _wire->search(deviceAddress)) {
161-
if (depth == index && validAddress(deviceAddress))
162-
return true;
163-
depth++;
160+
while (depth <= index && _wire->search(deviceAddress)) {
161+
if (depth == index && validAddress(deviceAddress))
162+
return true;
163+
depth++;
164+
}
164165
}
165166

166167
return false;
167-
168168
}
169169

170170
// attempt to determine if the device at the given address is connected to the bus

0 commit comments

Comments
 (0)