Fix: length more than LFS_FILE_MAX should return error

To make lfs_file_truncate inline with ftruncate function, when -ve
or size more than maximum file size is passed to function it should
return invalid parameter error. In LFS case LFS_ERR_INVAL.

Signed-off-by: Ajay Bhargav <contact@rickeyworld.info>
This commit is contained in:
Ajay Bhargav
2019-02-17 17:09:58 +05:30
committed by Christopher Haster
parent 0907ba7813
commit 905727b684

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