diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2020-11-05 17:26:13 +0000 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2020-11-05 18:01:26 +0000 |
commit | 2f93a2a03a343a29f614a530d7657f1ed6347ed5 (patch) | |
tree | 123d81efebe07a7e284cb2bc6a3dc134e9ff5a35 /libstdc++-v3/testsuite/experimental/filesystem | |
parent | 710508c7b1a2c8e1d75d4c4f1ac79473dbf2b2bb (diff) |
libstdc++: Use non-throwing increment in recursive_directory_iterator [PR 97731]
As described in the PR, the recursive_directory_iterator constructor
calls advance(ec), but ec is a pointer so it calls _Dir::advance(bool).
The intention was to either call advance() or advance(*ec) depending
whether the pointer is null or not.
This fixes the bug and renames the parameter to ecptr to make similar
mistakes less likely in future.
libstdc++-v3/ChangeLog:
PR libstdc++/97731
* src/filesystem/dir.cc (recursive_directory_iterator): Call the
right overload of _Dir::advance.
* testsuite/experimental/filesystem/iterators/97731.cc: New test.
Diffstat (limited to 'libstdc++-v3/testsuite/experimental/filesystem')
-rw-r--r-- | libstdc++-v3/testsuite/experimental/filesystem/iterators/97731.cc | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/experimental/filesystem/iterators/97731.cc b/libstdc++-v3/testsuite/experimental/filesystem/iterators/97731.cc new file mode 100644 index 00000000000..c6a9d5663fe --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/filesystem/iterators/97731.cc @@ -0,0 +1,49 @@ +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-DUSE_FILESYSTEM_TS -lstdc++fs" } +// { dg-do run { target c++11 } } +// { dg-require-filesystem-ts "" } + +#include <experimental/filesystem> +#include <cerrno> +#include <testsuite_hooks.h> + +bool used_custom_readdir = false; + +extern "C" void* readdir(void*) +{ + used_custom_readdir = true; + errno = EIO; + return nullptr; +} + +void +test01() +{ + using std::experimental::filesystem::recursive_directory_iterator; + std::error_code ec; + recursive_directory_iterator it(".", ec); + if (used_custom_readdir) + VERIFY( ec.value() == EIO ); +} + +int +main() +{ + test01(); +} |