Fix case where EEPROM will try to return longer string than it should

Fixes: https://github.com/espressif/arduino-esp32/issues/4768
This commit is contained in:
me-no-dev 2021-02-24 18:47:11 +02:00
parent 419ba32432
commit 5d00b6eb16

View File

@ -382,6 +382,9 @@ size_t EEPROMClass::readString (int address, char* value, size_t maxLen)
if (address + len > _size) if (address + len > _size)
return 0; return 0;
if (len > maxLen)
return 0; //Maybe return part of the string instead?
memcpy((uint8_t*) value, _data + address, len); memcpy((uint8_t*) value, _data + address, len);
value[len] = 0; value[len] = 0;
return len; return len;
@ -400,7 +403,7 @@ String EEPROMClass::readString (int address)
if (address + len > _size) if (address + len > _size)
return String(); return String();
char value[len]; char value[len+1];
memcpy((uint8_t*) value, _data + address, len); memcpy((uint8_t*) value, _data + address, len);
value[len] = 0; value[len] = 0;
return String(value); return String(value);