From 932666a03f3a2fce5a92018c4fbe316b1c77cbc5 Mon Sep 17 00:00:00 2001 From: lbernstone Date: Fri, 26 Apr 2019 10:39:22 -0600 Subject: [PATCH] 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 --- libraries/EEPROM/src/EEPROM.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libraries/EEPROM/src/EEPROM.cpp b/libraries/EEPROM/src/EEPROM.cpp index ac7dd72f..56282976 100644 --- a/libraries/EEPROM/src/EEPROM.cpp +++ b/libraries/EEPROM/src/EEPROM.cpp @@ -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; }