public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/99805] [9/10 Regression] filesystem::path::parent_path got a wrong path Date: Thu, 08 Apr 2021 17:00:05 +0000 [thread overview] Message-ID: <bug-99805-4-rjWhjUcENA@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-99805-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99805 --- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The releases/gcc-10 branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>: https://gcc.gnu.org/g:beb485ddeb066d03b2568bb1bebaa2902b4dbf97 commit r10-9671-gbeb485ddeb066d03b2568bb1bebaa2902b4dbf97 Author: Jonathan Wakely <jwakely@redhat.com> Date: Wed Apr 7 16:05:42 2021 +0100 libstdc++: Fix filesystem::path construction from COW string [PR 99805] Calling the non-const data() member on a COW string makes it "leaked", possibly resulting in reallocating the string to ensure a unique owner. The path::_M_split_cmpts() member parses its _M_pathname string using string_view objects and then calls _M_pathname.data() to find the offset of each string_view from the start of the string. However because _M_pathname is non-const that will cause a COW string to reallocate if it happens to be shared with another string object. This results in the offsets calculated for each component being wrong (i.e. undefined) because the string views no longer refer to substrings of the _M_pathname member. The fix is to use the parse.offset(c) member which gets the offset safely. The bug only happens for the path(string_type&&) constructor and only for COW strings. When constructed from an lvalue string the string's contents are copied rather than just incrementing the refcount, so there's no reallocation when calling the non-const data() member. The testsuite changes check the lvalue case anyway, because we should probably change the deep copying to just be a refcount increment (by adding a path(const string_type&) constructor or an overload for __effective_range(const string_type&), for COW strings only). libstdc++-v3/ChangeLog: PR libstdc++/99805 * src/c++17/fs_path.cc (path::_M_split_cmpts): Do not call non-const member on _M_pathname, to avoid copy-on-write. * testsuite/27_io/filesystem/path/decompose/parent_path.cc: Check construction from strings that might be shared. (cherry picked from commit e06d3f5dd7d0c6b4a20fe813e6ee5addd097f560)
next prev parent reply other threads:[~2021-04-08 17:00 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-03-29 3:05 [Bug c++/99805] New: " drfeng08 at gmail dot com 2021-03-29 15:15 ` [Bug c++/99805] " redi at gcc dot gnu.org 2021-04-01 6:15 ` drfeng08 at gmail dot com 2021-04-01 18:02 ` redi at gcc dot gnu.org 2021-04-01 18:03 ` [Bug c++/99805] [9/10/11 Regression] " redi at gcc dot gnu.org 2021-04-01 20:46 ` redi at gcc dot gnu.org 2021-04-01 21:06 ` redi at gcc dot gnu.org 2021-04-07 15:40 ` cvs-commit at gcc dot gnu.org 2021-04-07 15:43 ` [Bug c++/99805] [9/10 " redi at gcc dot gnu.org 2021-04-08 17:00 ` cvs-commit at gcc dot gnu.org [this message] 2021-04-08 17:04 ` [Bug c++/99805] [9 " redi at gcc dot gnu.org 2021-04-19 11:31 ` cvs-commit at gcc dot gnu.org 2021-04-19 11:31 ` redi at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-99805-4-rjWhjUcENA@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).