Skip to content

Commit c5e2b33

Browse files
committed
Added error when opening multiple files with a statically allocated buffer
Opening multiple files simultaneously is not supported without dynamic memory, but the previous behaviour would just let the files overwrite each other, which could lead to bad errors down the line found by husigeza
1 parent 015b86b commit c5e2b33

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

lfs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,10 @@ int lfs_file_open(lfs_t *lfs, lfs_file_t *file,
13351335
// allocate buffer if needed
13361336
file->cache.block = 0xffffffff;
13371337
if (lfs->cfg->file_buffer) {
1338+
if (lfs->files) {
1339+
// already in use
1340+
return LFS_ERR_NOMEM;
1341+
}
13381342
file->cache.buffer = lfs->cfg->file_buffer;
13391343
} else if ((file->flags & 3) == LFS_O_RDONLY) {
13401344
file->cache.buffer = lfs_malloc(lfs->cfg->read_size);

0 commit comments

Comments
 (0)