Skip to content

Commit

Permalink
Ensure that _size is properly set in begin (#2706)
Browse files Browse the repository at this point in the history
* Ensure that _size is properly set in begin

* NULL check on _data assignment

* Changed _data to malloc in order to catch alloc fails
  • Loading branch information
lbernstone authored and me-no-dev committed Apr 26, 2019
1 parent a0ad987 commit 932666a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion libraries/EEPROM/src/EEPROM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,12 @@ bool EEPROMClass::begin(size_t size) {
delete[] _data;
}

_data = new uint8_t[size];
_data = (uint8_t*) malloc(size);
if(!_data) {
log_e("Not enough memory for %d bytes in EEPROM");
return false;
}
_size = size;
nvs_get_blob(_handle, _name, _data, &_size);
return true;
}
Expand Down

0 comments on commit 932666a

Please sign in to comment.