Skip to content

Commit 932666a

Browse files
lbernstoneme-no-dev
authored andcommitted
Ensure that _size is properly set in begin (#2706)
* Ensure that _size is properly set in begin * NULL check on _data assignment * Changed _data to malloc in order to catch alloc fails
1 parent a0ad987 commit 932666a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Diff for: libraries/EEPROM/src/EEPROM.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,12 @@ bool EEPROMClass::begin(size_t size) {
130130
delete[] _data;
131131
}
132132

133-
_data = new uint8_t[size];
133+
_data = (uint8_t*) malloc(size);
134+
if(!_data) {
135+
log_e("Not enough memory for %d bytes in EEPROM");
136+
return false;
137+
}
138+
_size = size;
134139
nvs_get_blob(_handle, _name, _data, &_size);
135140
return true;
136141
}

0 commit comments

Comments
 (0)