[Bug libstdc++/90857] New: stl::forward_list::erase_after crashes if __pos == __last

jose.dapena at lge dot com gcc-bugzilla@gcc.gnu.org
Wed Jun 12 09:33:00 GMT 2019


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

            Bug ID: 90857
           Summary: stl::forward_list::erase_after crashes if __pos ==
                    __last
           Product: gcc
           Version: 8.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jose.dapena at lge dot com
  Target Milestone: ---

Created attachment 46483
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46483&action=edit
Test case

In case we invoke erase_after with __pos == __last, then it will crash, as
first thing erase_after implementation does is pointing to __pos next element,
then it iterates comparing that element to __last. As at that point the current
pointer will be already after __last, it will crash.

As far as I know, the specification does not really say this is a valid case.
But still it seams fair to at least check this case and make erase_after no-op
in this case (just returning an iterator pointing to the same node __pos points
too). This is the behavior in LLVM libc++.


More information about the Gcc-bugs mailing list