-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Fix arguments of dispatched functions cannot be actually moved #7873
base: RC_2_0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,6 +3,7 @@ | |||||
Copyright (c) 2014-2018, Steven Siloti | ||||||
Copyright (c) 2015-2018, Alden Torres | ||||||
Copyright (c) 2015-2022, Arvid Norberg | ||||||
Copyright (c) 2025, Vladimir Golovnev (glassez) | ||||||
All rights reserved. | ||||||
|
||||||
Redistribution and use in source and binary forms, with or without | ||||||
|
@@ -92,12 +93,12 @@ | |||||
{ | ||||||
std::shared_ptr<session_impl> s = m_impl.lock(); | ||||||
if (!s) aux::throw_ex<system_error>(errors::invalid_session_handle); | ||||||
dispatch(s->get_context(), [=]() mutable | ||||||
dispatch(s->get_context(), std::bind([s, f](auto&&... args) mutable | ||||||
Check notice Code scanning / CodeQL Unused local variable Note
Variable args is not used.
Check notice Code scanning / CodeQL Declaration hides parameter Note
Local variable 'args' hides a
parameter of the same name Error loading related location Loading There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be beneficial to move function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Generally, yes. But in this case, it is intended only for pointer to member function, so moving it will not add any advantages. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. So it is a pointer rather than a function object... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It is incorrect. |
||||||
{ | ||||||
#ifndef BOOST_NO_EXCEPTIONS | ||||||
try { | ||||||
#endif | ||||||
(s.get()->*f)(std::forward<Args>(a)...); | ||||||
(s.get()->*f)(std::forward<Args>(args)...); | ||||||
glassez marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
#ifndef BOOST_NO_EXCEPTIONS | ||||||
} catch (system_error const& e) { | ||||||
s->alerts().emplace_alert<session_error_alert>(e.code(), e.what()); | ||||||
|
@@ -107,7 +108,7 @@ | |||||
s->alerts().emplace_alert<session_error_alert>(error_code(), "unknown error"); | ||||||
} | ||||||
#endif | ||||||
}); | ||||||
}, std::forward<Args>(a)...)); | ||||||
} | ||||||
|
||||||
template<typename Fun, typename... Args> | ||||||
|
@@ -122,12 +123,12 @@ | |||||
bool done = false; | ||||||
|
||||||
std::exception_ptr ex; | ||||||
dispatch(s->get_context(), [=, &done, &ex]() mutable | ||||||
dispatch(s->get_context(), std::bind([s, f, &done, &ex](auto&&... args) mutable | ||||||
{ | ||||||
#ifndef BOOST_NO_EXCEPTIONS | ||||||
try { | ||||||
#endif | ||||||
(s.get()->*f)(std::forward<Args>(a)...); | ||||||
(s.get()->*f)(std::forward<Args>(args)...); | ||||||
glassez marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
#ifndef BOOST_NO_EXCEPTIONS | ||||||
} catch (...) { | ||||||
ex = std::current_exception(); | ||||||
|
@@ -136,7 +137,7 @@ | |||||
std::unique_lock<std::mutex> l(s->mut); | ||||||
done = true; | ||||||
s->cond.notify_all(); | ||||||
}); | ||||||
}, std::forward<Args>(a)...)); | ||||||
|
||||||
aux::torrent_wait(done, *s); | ||||||
if (ex) std::rethrow_exception(ex); | ||||||
|
@@ -154,12 +155,12 @@ | |||||
bool done = false; | ||||||
Ret r; | ||||||
std::exception_ptr ex; | ||||||
dispatch(s->get_context(), [=, &r, &done, &ex]() mutable | ||||||
dispatch(s->get_context(), std::bind([s, f, &r, &done, &ex](auto&&... args) mutable | ||||||
Check notice Code scanning / CodeQL Unused static variable Note
Static variable args is never read.
Check notice Code scanning / CodeQL Unused local variable Note
Variable args is not used.
Check notice Code scanning / CodeQL Declaration hides parameter Note
Local variable 'args' hides a
parameter of the same name Error loading related location Loading |
||||||
{ | ||||||
#ifndef BOOST_NO_EXCEPTIONS | ||||||
try { | ||||||
#endif | ||||||
r = (s.get()->*f)(std::forward<Args>(a)...); | ||||||
r = (s.get()->*f)(std::forward<Args>(args)...); | ||||||
glassez marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
#ifndef BOOST_NO_EXCEPTIONS | ||||||
} catch (...) { | ||||||
ex = std::current_exception(); | ||||||
|
@@ -168,7 +169,7 @@ | |||||
std::unique_lock<std::mutex> l(s->mut); | ||||||
done = true; | ||||||
s->cond.notify_all(); | ||||||
}); | ||||||
}, std::forward<Args>(a)...)); | ||||||
|
||||||
aux::torrent_wait(done, *s); | ||||||
if (ex) std::rethrow_exception(ex); | ||||||
|
@@ -426,8 +427,7 @@ | |||||
handle_backwards_compatible_resume_data(params); | ||||||
#endif | ||||||
error_code ec; | ||||||
auto ecr = std::ref(ec); | ||||||
torrent_handle r = sync_call_ret<torrent_handle>(&session_impl::add_torrent, std::move(params), ecr); | ||||||
torrent_handle r = sync_call_ret<torrent_handle>(&session_impl::add_torrent, std::move(params), std::ref(ec)); | ||||||
glassez marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
if (ec) aux::throw_ex<system_error>(ec); | ||||||
return r; | ||||||
} | ||||||
|
@@ -460,8 +460,7 @@ | |||||
#if TORRENT_ABI_VERSION == 1 | ||||||
handle_backwards_compatible_resume_data(params); | ||||||
#endif | ||||||
auto ecr = std::ref(ec); | ||||||
return sync_call_ret<torrent_handle>(&session_impl::add_torrent, std::move(params), ecr); | ||||||
return sync_call_ret<torrent_handle>(&session_impl::add_torrent, std::move(params), std::ref(ec)); | ||||||
} | ||||||
|
||||||
torrent_handle session_handle::add_torrent(add_torrent_params const& params, error_code& ec) | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ Copyright (c) 2005, 2007-2010, 2012-2022, Arvid Norberg | |
Copyright (c) 2016, 2018, Alden Torres | ||
Copyright (c) 2016, Andrei Kurushin | ||
Copyright (c) 2016-2018, Steven Siloti | ||
Copyright (c) 2016, Vladimir Golovnev | ||
Copyright (c) 2016, 2025, Vladimir Golovnev (glassez) | ||
Copyright (c) 2018, d-komarov | ||
All rights reserved. | ||
|
||
|
@@ -928,11 +928,12 @@ void test_fastresume(bool const test_deprecated) | |
p.storage_mode = storage_mode_sparse; | ||
error_code ignore; | ||
torrent_handle h = ses.add_torrent(std::move(p), ignore); | ||
TEST_CHECK(exists(combine_path(p.save_path, "temporary"))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is noteworthy that this "use-after-move" bug also went unnoticed, as |
||
if (!exists(combine_path(p.save_path, "temporary"))) | ||
|
||
torrent_status s = h.status(); | ||
TEST_CHECK(exists(combine_path(s.save_path, "temporary"))); | ||
if (!exists(combine_path(s.save_path, "temporary"))) | ||
return; | ||
|
||
torrent_status s; | ||
for (int i = 0; i < 50; ++i) | ||
{ | ||
print_alerts(ses, "ses"); | ||
|
Check notice
Code scanning / CodeQL
Unused static variable Note