Skip to content

Commit

Permalink
fix off-by-one at the end of EEPROM
Browse files Browse the repository at this point in the history
  • Loading branch information
wilhelmy committed Dec 18, 2016
1 parent a8375d4 commit 2378f6d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions ibutton.ino
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,22 @@ uint32_t hash_addr(byte (&addr)[8])
void learn_ibutton(byte (&addr)[8])
{
size_t i, base;
bool found = false;
uint32_t hash = hash_addr(addr);

for (i = 0; i < EEPROM_SIZE/4; i++) {
base = i*4;
if (EEPROM.read(base ) == 0xFF &&
EEPROM.read(base+1) == 0xFF &&
EEPROM.read(base+2) == 0xFF &&
EEPROM.read(base+3) == 0xFF)
break;
EEPROM.read(base+3) == 0xFF) {

found = true;
break;
}
}

if (i == EEPROM_SIZE/4) {
if (!found) {
debug("Error: Out of EEPROM space!\r\n");
return;
}
Expand Down

0 comments on commit 2378f6d

Please sign in to comment.