mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
764eef59cd
The old RoundUp formula `fsize + fsize % size` was incorrect. For
example, `truncate -s %128K` on a 24696-byte file produced 49392
bytes instead of the correct 131072 bytes.
This was incidentally fixed in commit fe9793331 ("truncate: eliminate
duplicate stat() syscall") by replacing the formula with
`fsize.checked_next_multiple_of(size)`. However, the existing test
`test_round_up` used values (fsize=10, size=4) where both the buggy
and correct formulas give the same result (12), so the bug was never
caught by the test suite.
Add unit and integration tests that would have caught this bug:
- File smaller than rounding unit (the reported scenario)
- File larger than rounding unit but not aligned
- File already aligned to the rounding unit
- Division by zero (RoundUp with size=0)
Link: https://review.trustedfirmware.org/c/TF-A/trusted-firmware-a/+/48210
Signed-off-by: Vincent Jardin <vjardin@free.fr>