Skip to content

Commit d1e9aa1

Browse files
committed
Force variable cleanup because LFS makes assumptions about variable initialization state
1 parent fdb5e27 commit d1e9aa1

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

src/components/ble/FSService.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) {
7171
}
7272
lfs_dir_t dir;
7373
lfs_info info;
74+
lfs_file f;
75+
memset(&f, 0, sizeof(lfs_file_t));
76+
memset(&dir, 0, sizeof(lfs_dir_t));
7477
switch (command) {
7578
case commands::READ: {
76-
lfs_file f;
7779
NRF_LOG_INFO("[FS_S] -> Read");
7880
auto* header = (ReadHeader*) om->om_data;
7981
uint16_t plen = header->pathlen;
@@ -109,7 +111,6 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) {
109111
break;
110112
}
111113
case commands::READ_PACING: {
112-
lfs_file f;
113114
NRF_LOG_INFO("[FS_S] -> Readpacing");
114115
auto* header = (ReadHeader*) om->om_data;
115116
ReadResponse resp;
@@ -142,7 +143,6 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) {
142143
break;
143144
}
144145
case commands::WRITE: {
145-
lfs_file f;
146146
NRF_LOG_INFO("[FS_S] -> Write");
147147
auto* header = (WriteHeader*) om->om_data;
148148
uint16_t plen = header->pathlen;
@@ -157,8 +157,8 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) {
157157
resp.offset = header->offset;
158158
resp.modTime = 0;
159159

160-
int res = fs.FileOpen(&f, filepath, LFS_O_WRONLY | LFS_O_CREAT);
161-
if(res == 0){
160+
int res = fs.FileOpen(&f, filepath, LFS_O_RDWR | LFS_O_CREAT);
161+
if (res == 0) {
162162
fs.FileClose(&f);
163163
resp.status = (res == 0) ? 0x01 : (int8_t) res;
164164
}
@@ -168,7 +168,6 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) {
168168
break;
169169
}
170170
case commands::WRITE_DATA: {
171-
lfs_file f;
172171
NRF_LOG_INFO("[FS_S] -> WriteData");
173172
auto* header = (WritePacing*) om->om_data;
174173
WriteResponse resp;
@@ -185,7 +184,6 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) {
185184
if (res < 0) {
186185
resp.status = (int8_t) res;
187186
}
188-
189187
resp.freespace = std::min(fs.getSize() - (fs.GetFSSize() * fs.getBlockSize()), fileSize - header->offset);
190188
auto* om = ble_hs_mbuf_from_flat(&resp, sizeof(WriteResponse));
191189
ble_gattc_notify_custom(connectionHandle, transferCharacteristicHandle, om);

0 commit comments

Comments
 (0)