diff options
author | Christopher Haster <chaster@utexas.edu> | 2018-04-29 16:45:14 +0300 |
---|---|---|
committer | Christopher Haster <chaster@utexas.edu> | 2018-04-30 11:37:10 +0300 |
commit | c5e2b335d618a78656a867c7874835db141fbad1 (patch) | |
tree | 476e5ec61617205d8af80180acf10973d9d41ab7 | |
parent | 015b86bc51fddbd9d0e7c68e02015f8fd12c5839 (diff) |
Added error when opening multiple files with a statically allocated bufferv1.3
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
-rw-r--r-- | lfs.c | 4 |
1 files changed, 4 insertions, 0 deletions
@@ -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); |