Skip to content
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

Use references explicitly, and avoid dangling references captured by … #924

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions include/crow/routing.h
Original file line number Diff line number Diff line change
Expand Up @@ -1725,7 +1725,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"

try
{
auto& rule = rules[rule_index];
BaseRule& rule = *rules[rule_index];
handle_rule<App>(rule, req, res, found.r_params);
}
catch (...)
Expand All @@ -1738,13 +1738,13 @@ namespace crow // NOTE: Already documented in "crow/app.h"

template<typename App>
typename std::enable_if<std::tuple_size<typename App::mw_container_t>::value != 0, void>::type
handle_rule(BaseRule* rule, crow::request& req, crow::response& res, const crow::routing_params& rp)
handle_rule(BaseRule& rule, crow::request& req, crow::response& res, const crow::routing_params& rp)
{
if (!rule->mw_indices_.empty())
if (!rule.mw_indices_.empty())
{
auto& ctx = *reinterpret_cast<typename App::context_t*>(req.middleware_context);
auto& container = *reinterpret_cast<typename App::mw_container_t*>(req.middleware_container);
detail::middleware_call_criteria_dynamic<false> crit_fwd(rule->mw_indices_.indices());
detail::middleware_call_criteria_dynamic<false> crit_fwd(rule.mw_indices_.indices());

auto glob_completion_handler = std::move(res.complete_request_handler_);
res.complete_request_handler_ = [] {};
Expand All @@ -1759,7 +1759,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
}

res.complete_request_handler_ = [&rule, &ctx, &container, &req, &res, glob_completion_handler] {
detail::middleware_call_criteria_dynamic<true> crit_bwd(rule->mw_indices_.indices());
detail::middleware_call_criteria_dynamic<true> crit_bwd(rule.mw_indices_.indices());

detail::after_handlers_call_helper<
decltype(crit_bwd),
Expand All @@ -1769,14 +1769,14 @@ namespace crow // NOTE: Already documented in "crow/app.h"
glob_completion_handler();
};
}
rule->handle(req, res, rp);
rule.handle(req, res, rp);
}

template<typename App>
typename std::enable_if<std::tuple_size<typename App::mw_container_t>::value == 0, void>::type
handle_rule(BaseRule* rule, crow::request& req, crow::response& res, const crow::routing_params& rp)
handle_rule(BaseRule& rule, crow::request& req, crow::response& res, const crow::routing_params& rp)
{
rule->handle(req, res, rp);
rule.handle(req, res, rp);
}

void debug_print()
Expand Down
Loading