public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "kip at thevertigo dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/99402] New: std::copy creates _GLIBCXX_DEBUG false positive for attempt to subscript a dereferenceable (start-of-sequence) iterator
Date: Fri, 05 Mar 2021 09:09:47 +0000	[thread overview]
Message-ID: <bug-99402-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99402

            Bug ID: 99402
           Summary: std::copy creates _GLIBCXX_DEBUG false positive for
                    attempt to subscript a dereferenceable
                    (start-of-sequence) iterator
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kip at thevertigo dot com
  Target Milestone: ---

The following is a minimal:

// Standard C++ / POSIX system headers...
#include <algorithm>
#include <set>
#include <vector>

using namespace std;

int main()
{
    // Container of eleven elements...
    const set<int> Source = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

    // Goal is to copy the first ten elements in to here, or 0 to 9 inclusive.
    //  It has space for ten elements...
    vector<int> Destination(10);

    // This should point to the end of the source range, or element with value
    //  10 which is the first value after the range to be copied...
    const auto EndIterator = next(cbegin(Source), 10);

    // This results in memory corruption, or an abort with STL debugging
    //  enabled. copy_n(..., 10, ...) works fine...
    copy(cbegin(Source), EndIterator, begin(Destination));

    return 0;
}

Compile and run with the following:

    $ g++-10 -D_GLIBCXX_DEBUG test.cpp -o test -g3 -std=c++17 && ./test 

I see the following:

    /usr/include/c++/10/bits/stl_algobase.h:566:
    In function:
        _OI std::copy(_II, _II, _OI) [with _II = 
        __gnu_debug::_Safe_iterator<std::_Rb_tree_const_iterator<int>, 
        std::__debug::set<int>, std::bidirectional_iterator_tag>; _OI = 
        __gnu_debug::_Safe_iterator<__gnu_cxx::__normal_iterator<int*, 
        std::__cxx1998::vector<int, std::allocator<int> > >, 
        std::__debug::vector<int>, std::random_access_iterator_tag>]

    Error: attempt to subscript a dereferenceable (start-of-sequence) iterator 
    11 step from its current position, which falls outside its dereferenceable 
    range.

    Objects involved in the operation:
        iterator "__result" @ 0x0x7ffc3a448040 {
          type = __gnu_cxx::__normal_iterator<int*, std::__cxx1998::vector<int,
std::allocator<int> > > (mutable iterator);
          state = dereferenceable (start-of-sequence);
          references sequence with type 'std::__debug::vector<int,
std::allocator<int> >' @ 0x0x7ffc3a4480d0
        }
    Aborted (core dumped)

I've been advised from another who ran the same test that this works fine with
GCC 8 and 9, so it may be a regression.

             reply	other threads:[~2021-03-05  9:09 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-05  9:09 kip at thevertigo dot com [this message]
2021-03-05 12:16 ` [Bug libstdc++/99402] [10/11 Regression] " redi at gcc dot gnu.org
2021-03-05 12:30 ` redi at gcc dot gnu.org
2021-03-05 12:33 ` redi at gcc dot gnu.org
2021-03-05 12:40 ` redi at gcc dot gnu.org
2021-03-05 12:55 ` redi at gcc dot gnu.org
2021-03-05 12:59 ` redi at gcc dot gnu.org
2021-03-05 19:26 ` fdumont at gcc dot gnu.org
2021-03-05 20:00 ` kip at thevertigo dot com
2021-04-08 12:02 ` rguenth at gcc dot gnu.org
2021-04-08 12:53 ` rguenth at gcc dot gnu.org
2021-04-13 20:51 ` [Bug libstdc++/99402] [10 " redi at gcc dot gnu.org
2021-04-13 22:19 ` kip at thevertigo dot com
2021-04-13 22:45 ` redi at gcc dot gnu.org
2021-04-23 12:02 ` fdumont at gcc dot gnu.org
2021-04-23 13:04 ` 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-99402-4@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: link
Be 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).