You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was having an issue with EEPROM.readString() always putting an extra junk byte at the end. It looks like this is a bug!
Specifically, these lines:
Assume len=10, then
char value[len + 1]; //SIZE is 11
memcpy((uint8_t*) value, _data + address, len); //we READ 10 bytes
value[len + 1] = 0; <- //WAIT! we are writing the null terminator at index 11!,
//that is the 12th byte in the array! We are writing out-of-bounds of the array! this means value[len]=? //because it is a byte from random memory!
Hi! Is this bug?
String EEPROMClass::readString (int address)
{
if (address < 0 || address > _size)
return String(0);
uint16_t len;
for (len = 0; len <= _size; len++)
if (_data[address + len] == 0)
break;
if (address + len > _size)
return String(0);
char value[len + 1];
memcpy((uint8_t*) value, _data + address, len);
value[len + 1] = 0; <- ????
return String(value);
}
The text was updated successfully, but these errors were encountered: