public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/99805] [9/10/11 Regression] filesystem::path::parent_path got a wrong path Date: Thu, 01 Apr 2021 20:46:58 +0000 [thread overview] Message-ID: <bug-99805-4-GTJQC8uqTt@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 #4 from Jonathan Wakely <redi at gcc dot gnu.org> --- Wow, this is tricksy. The bug happens when parsing the string into a path. The path is split into components and the offset of each component from the beginning of the string is stored, so that parent_path() can efficiently erase the part of the native() string that refers to the last component. The offset is calculated like this: for (auto& c : buf) { auto pos = c.str.data() - _M_pathname.data(); ::new(output++) _Cmpt(c.str, c.type, pos); ++_M_cmpts._M_impl->_M_size; } The bug is that for the COW std::string _M_pathname.data() causes the string to be reallocated, and so changes the address at which the string is stored. So the string_view c.str no longer refers to the same data as _M_pathname. We get a bogus offset for the components, and when we try to remove the last component to get the parent_path(), we don't remove anything from the string.
next prev parent reply other threads:[~2021-04-01 20:46 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 [this message] 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 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-GTJQC8uqTt@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).