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/src | |
parent | 710508c7b1a2c8e1d75d4c4f1ac79473dbf2b2bb (diff) | |
download | gcc-2f93a2a03a343a29f614a530d7657f1ed6347ed5.zip gcc-2f93a2a03a343a29f614a530d7657f1ed6347ed5.tar.gz gcc-2f93a2a03a343a29f614a530d7657f1ed6347ed5.tar.bz2 |
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/src')
-rw-r--r-- | libstdc++-v3/src/filesystem/dir.cc | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/libstdc++-v3/src/filesystem/dir.cc b/libstdc++-v3/src/filesystem/dir.cc index 86aee2d..5109897 100644 --- a/libstdc++-v3/src/filesystem/dir.cc +++ b/libstdc++-v3/src/filesystem/dir.cc @@ -187,16 +187,16 @@ struct fs::recursive_directory_iterator::_Dir_stack : std::stack<_Dir> fs::recursive_directory_iterator:: recursive_directory_iterator(const path& p, directory_options options, - error_code* ec) + error_code* ecptr) : _M_options(options), _M_pending(true) { - if (ec) - ec->clear(); if (posix::DIR* dirp = posix::opendir(p.c_str())) { + if (ecptr) + ecptr->clear(); auto sp = std::make_shared<_Dir_stack>(); sp->push(_Dir{ dirp, p }); - if (sp->top().advance(ec)) + if (ecptr ? sp->top().advance(*ecptr) : sp->top().advance()) _M_dirs.swap(sp); } else @@ -204,14 +204,18 @@ recursive_directory_iterator(const path& p, directory_options options, const int err = errno; if (err == EACCES && is_set(options, fs::directory_options::skip_permission_denied)) - return; + { + if (ecptr) + ecptr->clear(); + return; + } - if (!ec) + if (!ecptr) _GLIBCXX_THROW_OR_ABORT(filesystem_error( "recursive directory iterator cannot open directory", p, std::error_code(err, std::generic_category()))); - ec->assign(err, std::generic_category()); + ecptr->assign(err, std::generic_category()); } } |