forked from airgradienthq/arduino
Fix get storage allocate based on size
This commit is contained in:
@ -1104,17 +1104,17 @@ void Measurements::saveLocalStorage(AirGradient &ag) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
char *Measurements::getLocalStorage() {
|
char *Measurements::getLocalStorage() {
|
||||||
char *buf = new char[1024];
|
char *buf = nullptr;
|
||||||
if (buf == nullptr) {
|
|
||||||
Serial.println("NEW getLocal buffer failed");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
memset(buf, 0, 1024);
|
|
||||||
|
|
||||||
// TODO: Buffer based on file size
|
|
||||||
bool success = false;
|
bool success = false;
|
||||||
File file = SPIFFS.open(FILE_PATH);
|
File file = SPIFFS.open(FILE_PATH);
|
||||||
if (file && !file.isDirectory()) {
|
if (file && !file.isDirectory()) {
|
||||||
|
// Allocate memory
|
||||||
|
buf = new char[file.size() + 1];
|
||||||
|
if (buf == nullptr) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
memset(buf, 0, file.size() + 1);
|
||||||
|
// Retrieve data from the file
|
||||||
if (file.readBytes(buf, file.size()) != file.size()) {
|
if (file.readBytes(buf, file.size()) != file.size()) {
|
||||||
Serial.println("Reading measurements file: failed - size not match");
|
Serial.println("Reading measurements file: failed - size not match");
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user