You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[cases.test_cur_int32max] and [cases.test_end_int32max] return different values for current cursor position depending on whether we use LFS_SEEK_CUR or LFS_SEEK_END (note that CUR should be equal to END, since no additional writes or seeks were performed, but returned value is different). The return value in both cases should be the same (either INT32_MAX (preferably) or 0).
[cases.test_ub_cur_int32max] and [cases.test_ub_set_int32max] work as expected (return error when seeking past LFS_FILE_MAX) but rely on undefined behaviour in lfs_file_seek (signed integer overflow), so they may not work as expected for every platform and compile options combination.
Ah, @m-kostrzewa actually there's an explanation for the first issue:
[cases.test_cur_int32max] and [cases.test_end_int32max] return different values for current cursor position depending on whether we use LFS_SEEK_CUR or LFS_SEEK_END (note that CUR should be equal to END, since no additional writes or seeks were performed, but returned value is different). The return value in both cases should be the same (either INT32_MAX (preferably) or 0).
This matches POSIX behavior in that seek changes the current position of the file pointer, but not the size of the file. The size is not changed until a write occurs on the file.
So when you seek to LFS_SEEK_END+0, it seeks to the end of the file, which is zero since no write occurred. If the file contained some data the LFS_SEEK_END+0 would return the end of the file.
In theory you could fill the file with zeros by writing a single byte at INT32_MAX-1, or with lfs_file_truncate(&lfs, &file, INT32_MAX), but littlefs doesn't currently support sparse files so this would quickly explode.
Hello,
consider these 4 test cases.
Checked on d01280e.
Proposed solution: compute temporary offset calculations in lfs_file_seek using int64_t before casting them to 32-bit values.
The text was updated successfully, but these errors were encountered: