Skip to content

Commit e47e3c7

Browse files
authored
Fix memcpy to unallocated memory in EEPROM.cpp (#1000)
The memcpy to unallocated memory was done in two cases: 1) The 'size' parameter was not multiple of 256. 2) The begin() was called two times and the 2nd call 'size' was greater than 1st time 'size'. (e.g. 1st size=256, 2nd size=512)
1 parent f11c22d commit e47e3c7

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

libraries/EEPROM/src/EEPROM.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void EEPROMClass::begin(size_t size) {
4545
size = 4096;
4646
}
4747

48-
_size = (size + 255) & (~255); // Flash writes limited to 256 byte boundaries
48+
size = (size + 255) & (~255); // Flash writes limited to 256 byte boundaries
4949

5050
// In case begin() is called a 2nd+ time, don't reallocate if size is the same
5151
if (_data && size != _size) {
@@ -55,6 +55,8 @@ void EEPROMClass::begin(size_t size) {
5555
_data = new uint8_t[size];
5656
}
5757

58+
_size = size;
59+
5860
memcpy(_data, _sector, _size);
5961

6062
_dirty = false; //make sure dirty is cleared in case begin() is called 2nd+ time

0 commit comments

Comments
 (0)