Force variable cleanup because LFS makes assumptions about variable initialization state

This commit is contained in:
Tim Keller 2021-11-21 06:17:07 +00:00
parent fdb5e27aea
commit d1e9aa1076

View file

@ -71,9 +71,11 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) {
} }
lfs_dir_t dir; lfs_dir_t dir;
lfs_info info; lfs_info info;
lfs_file f;
memset(&f, 0, sizeof(lfs_file_t));
memset(&dir, 0, sizeof(lfs_dir_t));
switch (command) { switch (command) {
case commands::READ: { case commands::READ: {
lfs_file f;
NRF_LOG_INFO("[FS_S] -> Read"); NRF_LOG_INFO("[FS_S] -> Read");
auto* header = (ReadHeader*) om->om_data; auto* header = (ReadHeader*) om->om_data;
uint16_t plen = header->pathlen; uint16_t plen = header->pathlen;
@ -109,7 +111,6 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) {
break; break;
} }
case commands::READ_PACING: { case commands::READ_PACING: {
lfs_file f;
NRF_LOG_INFO("[FS_S] -> Readpacing"); NRF_LOG_INFO("[FS_S] -> Readpacing");
auto* header = (ReadHeader*) om->om_data; auto* header = (ReadHeader*) om->om_data;
ReadResponse resp; ReadResponse resp;
@ -142,7 +143,6 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) {
break; break;
} }
case commands::WRITE: { case commands::WRITE: {
lfs_file f;
NRF_LOG_INFO("[FS_S] -> Write"); NRF_LOG_INFO("[FS_S] -> Write");
auto* header = (WriteHeader*) om->om_data; auto* header = (WriteHeader*) om->om_data;
uint16_t plen = header->pathlen; uint16_t plen = header->pathlen;
@ -157,8 +157,8 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) {
resp.offset = header->offset; resp.offset = header->offset;
resp.modTime = 0; resp.modTime = 0;
int res = fs.FileOpen(&f, filepath, LFS_O_WRONLY | LFS_O_CREAT); int res = fs.FileOpen(&f, filepath, LFS_O_RDWR | LFS_O_CREAT);
if(res == 0){ if (res == 0) {
fs.FileClose(&f); fs.FileClose(&f);
resp.status = (res == 0) ? 0x01 : (int8_t) res; resp.status = (res == 0) ? 0x01 : (int8_t) res;
} }
@ -168,7 +168,6 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) {
break; break;
} }
case commands::WRITE_DATA: { case commands::WRITE_DATA: {
lfs_file f;
NRF_LOG_INFO("[FS_S] -> WriteData"); NRF_LOG_INFO("[FS_S] -> WriteData");
auto* header = (WritePacing*) om->om_data; auto* header = (WritePacing*) om->om_data;
WriteResponse resp; WriteResponse resp;
@ -185,7 +184,6 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) {
if (res < 0) { if (res < 0) {
resp.status = (int8_t) res; resp.status = (int8_t) res;
} }
resp.freespace = std::min(fs.getSize() - (fs.GetFSSize() * fs.getBlockSize()), fileSize - header->offset); resp.freespace = std::min(fs.getSize() - (fs.GetFSSize() * fs.getBlockSize()), fileSize - header->offset);
auto* om = ble_hs_mbuf_from_flat(&resp, sizeof(WriteResponse)); auto* om = ble_hs_mbuf_from_flat(&resp, sizeof(WriteResponse));
ble_gattc_notify_custom(connectionHandle, transferCharacteristicHandle, om); ble_gattc_notify_custom(connectionHandle, transferCharacteristicHandle, om);