Skip to content

Commit 9b65398

Browse files
committed
fix possible null ptr in EEPROM.cpp
1 parent 5c60dcb commit 9b65398

File tree

1 file changed

+10
-3
lines changed
  • hardware/esp8266com/esp8266/libraries/EEPROM

1 file changed

+10
-3
lines changed

hardware/esp8266com/esp8266/libraries/EEPROM/EEPROM.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ EEPROMClass::EEPROMClass()
4141

4242
void EEPROMClass::begin(size_t size)
4343
{
44-
if (size < 0)
44+
if (size <= 0)
4545
return;
4646
if (size > SPI_FLASH_SEC_SIZE)
4747
size = SPI_FLASH_SEC_SIZE;
@@ -60,8 +60,9 @@ void EEPROMClass::end()
6060
return;
6161

6262
commit();
63-
64-
delete[] _data;
63+
if(_data) {
64+
delete[] _data;
65+
}
6566
_data = 0;
6667
_size = 0;
6768
}
@@ -71,6 +72,8 @@ uint8_t EEPROMClass::read(int address)
7172
{
7273
if (address < 0 || (size_t)address >= _size)
7374
return 0;
75+
if(!_data)
76+
return 0;
7477

7578
return _data[address];
7679
}
@@ -79,6 +82,8 @@ void EEPROMClass::write(int address, uint8_t value)
7982
{
8083
if (address < 0 || (size_t)address >= _size)
8184
return;
85+
if(!_data)
86+
return;
8287

8388
_data[address] = value;
8489
_dirty = true;
@@ -91,6 +96,8 @@ bool EEPROMClass::commit()
9196
return false;
9297
if(!_dirty)
9398
return true;
99+
if(!_data)
100+
return false;
94101

95102
noInterrupts();
96103
if(spi_flash_erase_sector(CONFIG_SECTOR) == SPI_FLASH_RESULT_OK) {

0 commit comments

Comments
 (0)