From 64a1997da34155eb49617e26455608e54b5b9182 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Sun, 29 Apr 2018 16:45:14 +0300 Subject: [PATCH] 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 --- lfs.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lfs.c b/lfs.c index 3aef9fc..f0c62a1 100644 --- a/lfs.c +++ b/lfs.c @@ -1355,6 +1355,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);