Repository navigation
Fix warnings and truncations around filesize_to_str() - #6987
Conversation
On 32-bit platforms, we would otherwise perform a 40-bit shift of a 32-bit size_t, which is undefined behaviour. Moreover, files can be larger than the address space of the process.
On non-Windows, print the errno when file exists but we couldn't open it. That will happen for files larger than the address space when off_t is 32-bit (default on Linux+glibc). In case an operating system does let us open a large file, check the size before casting it to size_t. (This happens at least on Windows.)
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #6987 +/- ##
=======================================
Coverage 98.69% 98.69%
=======================================
Files 79 79
Lines 14678 14678
=======================================
Hits 14487 14487
Misses 191 191 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Generated via commit d462ecf Download link for the artifact containing the test results: ↓ atime-results.zip
|
|
Before merging this we could possibly add check to CI which detects compilation warnings also on Mac, now we have one for Linux. |
|
I think this warrants a NEWS entry since it could be user-facing |
I want to avoid piling in unrelated edits to PRs, it makes the git history a lot harder to understand. Just this week we had to try and parse out why a certain change was made in an unrelated 7+-year-old PR & guess based on PR comments: Since I don't think it's a blocking issue, I filed #6990. |
Co-authored-by: Michael Chirico <chiricom@google.com>
Co-authored-by: Michael Chirico <chiricom@google.com>
|
Yes, writing the NEWS made me realise how unrelated were the fixes. Sorry. Will apply the Boy Scout Rule less liberally in the future. I can split the PR if needed. |
- Make sure to use the right platform-specific variable in both cases - Can't use filesize_to_str() more than once due to its static buffer
|
Thanks! |

Performing a 40-bit shift on a 32-bit
size_tis undefined behaviour; things go downhill from there. Acceptuint64_tinstead ofsize_tfor a file size, since it's still possible for a file to exceed the address space in size.size_twas passed to thePRIu64size specifier:This warning ends up being harmless even on 32-bit systems, but it's still undefined behaviour.
glibc, we default to 32-bitoff_tand thus fail to open files that are too large, but guard against this anyway in case some other POSIX system behaves differently.