diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2018-05-03 19:58:00 +0100 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2018-05-03 19:58:00 +0100 |
commit | 2e023647c8e5733305471da13cc5144e1cc3d42b (patch) | |
tree | 17215da3d46876570a25807283d69460939f54a6 /libstdc++-v3/src/filesystem/ops.cc | |
parent | d18734b5adea54ddd004e51b8d2593752133596c (diff) | |
download | gcc-2e023647c8e5733305471da13cc5144e1cc3d42b.tar.gz |
PR libstdc++/85632 fix wraparound in filesystem::space
On 32-bit targets any values over 4GB would wrap and produce the wrong
result.
PR libstdc++/85632 use uintmax_t for arithmetic
* src/filesystem/ops.cc (experimental::filesystem::space): Perform
arithmetic in result type.
* src/filesystem/std-ops.cc (filesystem::space): Likewise.
* testsuite/27_io/filesystem/operations/space.cc: Check total capacity
is greater than free space.
* testsuite/experimental/filesystem/operations/space.cc: New.
From-SVN: r259901
Diffstat (limited to 'libstdc++-v3/src/filesystem/ops.cc')
-rw-r--r-- | libstdc++-v3/src/filesystem/ops.cc | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/libstdc++-v3/src/filesystem/ops.cc b/libstdc++-v3/src/filesystem/ops.cc index 328332a8a82..4a9e265d1d6 100644 --- a/libstdc++-v3/src/filesystem/ops.cc +++ b/libstdc++-v3/src/filesystem/ops.cc @@ -1132,10 +1132,11 @@ fs::space(const path& p, error_code& ec) noexcept ec.assign(errno, std::generic_category()); else { + uintmax_t fragment_size = f.f_frsize; info = space_info{ - f.f_blocks * f.f_frsize, - f.f_bfree * f.f_frsize, - f.f_bavail * f.f_frsize + f.f_blocks * fragment_size, + f.f_bfree * fragment_size, + f.f_bavail * fragment_size }; ec.clear(); } |