Skip to content

Commit

Permalink
Added error when opening multiple files with a statically allocated b…
Browse files Browse the repository at this point in the history
…uffer

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
  • Loading branch information
geky committed Apr 30, 2018
1 parent 015b86b commit c5e2b33
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,10 @@ int lfs_file_open(lfs_t *lfs, lfs_file_t *file,
// allocate buffer if needed
file->cache.block = 0xffffffff;
if (lfs->cfg->file_buffer) {
if (lfs->files) {
// already in use
return LFS_ERR_NOMEM;
}
file->cache.buffer = lfs->cfg->file_buffer;
} else if ((file->flags & 3) == LFS_O_RDONLY) {
file->cache.buffer = lfs_malloc(lfs->cfg->read_size);
Expand Down

0 comments on commit c5e2b33

Please sign in to comment.