[libcxx-commits] [PATCH] D152327: [libc++] Fix an exception safety issue in `forward_list` and add tests.

Konstantin Varlamov via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jun 6 18:20:41 PDT 2023


var-const created this revision.
Herald added a project: All.
var-const requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

When inserting nodes into a forward list, each new node is allocated but
not constructed. The constructor was being called explicitly on the node
`value_` but the `next_` pointer remained uninitialized rather than
being set to null. This bug is only triggered in the cleanup code if an
exception is thrown -- upon successful creation of new nodes, the last
incorrect "next" value is overwritten to a correct pointer.

This issue was found due to new tests added in
https://reviews.llvm.org/D149830.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152327

Files:
  libcxx/include/forward_list
  libcxx/test/std/containers/container.adaptors/from_range_container_adaptors.h
  libcxx/test/std/containers/container.adaptors/push_range_container_adaptors.h
  libcxx/test/std/containers/exception_safety_helpers.h
  libcxx/test/std/containers/from_range_helpers.h
  libcxx/test/std/containers/sequences/forwardlist/robust_against_exceptions.pass.cpp
  libcxx/test/std/containers/sequences/from_range_sequence_containers.h
  libcxx/test/std/containers/sequences/insert_range_sequence_containers.h

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152327.529115.patch
Type: text/x-patch
Size: 18263 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230607/3aafd576/attachment-0001.bin>


More information about the libcxx-commits mailing list