Title
Issues with join_with_view::iterator's iter_swap
Status
new
Section
[range.join.with.iterator]
Submitter
Hewill Kang

Created on 2023-09-04.00:00:00 last changed 5 months ago

Messages

Date: 2023-11-15.00:00:00

[ 2023-11-02; Reflector poll ]

Set priority to 2 after reflector poll.

Date: 2023-09-04.00:00:00

The iter_swap customization for join_with_view::iterator allows swapping iterators with different element types, potentially leading to unsafe behavior, for example:

vector<vector<string>> x{{"a"}, {"b"}, {"c"}};
vector<string_view>    y{"-"};
auto r = x | views::join_with(y);
auto i = r.begin();
auto j = ranges::next(i);
ranges::iter_swap(j, i);
for (auto&& elem : r)
  cout << elem << " "; // AddressSanitizer: stack-use-after-return on address

The above swaps two iterators whose reference are string_view& and string& respectively, which ultimately results in string_view being referenced to a local variable and left dangling.

History
Date User Action Args
2023-11-03 18:08:28adminsetmessages: + msg13803
2023-09-04 00:00:00admincreate