Merge pull request #150 from ajaybhargav/truncate-fix

Fix: length more than LFS_FILE_MAX should return error
This commit is contained in:
Christopher Haster
2019-04-12 17:06:58 -05:00
committed by GitHub

4
lfs.c
View File

@@ -2864,6 +2864,10 @@ int lfs_file_truncate(lfs_t *lfs, lfs_file_t *file, lfs_off_t size) {
return LFS_ERR_BADF; return LFS_ERR_BADF;
} }
if (size > LFS_FILE_MAX) {
return LFS_ERR_INVAL;
}
lfs_off_t oldsize = lfs_file_size(lfs, file); lfs_off_t oldsize = lfs_file_size(lfs, file);
if (size < oldsize) { if (size < oldsize) {
// need to flush since directly changing metadata // need to flush since directly changing metadata