-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possible use-after-move in join() #4231
Comments
I'm a bit out of my depth but maybe something like: auto value_copy = std::forward<view_ref>(value);
auto it = std::move(value_copy.begin);
// rest of the code uses value_copy though this forces a copy even in the good case. |
I had a look at this. I believe this specialization is only used for exactly If you try and pass an lvalue So now we can be sure that this code path only deals with receiving This Lines 2214 to 2225 in 720da57
This means that line 2224's first argument passed to
A minimal fix is to change template <typename FormatContext>
auto format(join_view<It, Sentinel, Char>& value, FormatContext& ctx) const
-> decltype(ctx.out()) {
auto& it = value.begin; This also saves a copy/move since we now take
Note this code was originally put in in 10508a30ecd91e5d09a27e4c6c0a01a89fd4edc7 and changed to If I've missed anything or my assumptions or wrong, please point it out
I can put in a PR for this if vitaut agrees this is a good change to make |
Thanks @mattgodbolt for reporting and @Arghnews for investigating the issue.
I think this is a correct fix.
Please do. |
Thank you both! |
Should fix fmtlib#4231 Could instead use: <!std::is_copy_constructible_v<It>, It&, It>;
The code at:
fmt/include/fmt/ranges.h
Lines 661 to 666 in 720da57
Does a
auto it = std::forward<view_ref>(value).begin;
and later accesses
value.end
andvalue.sep
.In the case the iterator is not copy constructible then the
view_ref
is an rvalue-reference:which effectively turns the
forward<>
into amove
.clang-tidy
warns on the accesses ofend
andsep
as they are accesses on a moved-from object.I'm not sure that this is really a problem in practice but it seems like something that should be avoided. I can't see an easy way to do so though. I'm not sure we can cast just the iterator easily? Taking a copy of
sep
works but for the same reasons as above we can't copyend
out without a move either.The text was updated successfully, but these errors were encountered: