diff --git a/include/crow/routing.h b/include/crow/routing.h index f1a544e9b..da8c20834 100644 --- a/include/crow/routing.h +++ b/include/crow/routing.h @@ -721,7 +721,6 @@ namespace crow // NOTE: Already documented in "crow/app.h" constexpr size_t RULE_SPECIAL_REDIRECT_SLASH = 1; - /// A search tree. class Trie { @@ -1317,7 +1316,9 @@ namespace crow // NOTE: Already documented in "crow/app.h" ruleObject->foreach_method([&](int method) { per_methods_[method].rules.emplace_back(ruleObject); - per_methods_[method].trie.add(rule, per_methods_[method].rules.size() - 1, BP_index != INVALID_BP_ID ? blueprints[BP_index]->prefix().length() : 0, BP_index); + per_methods_[method].trie.add(rule, per_methods_[method].rules.size() - 1, + BP_index != INVALID_BP_ID ? blueprints[BP_index]->prefix().length() : 0, + BP_index); // directory case: // request to '/about' url matches '/about/' rule @@ -1528,11 +1529,12 @@ namespace crow // NOTE: Already documented in "crow/app.h" CatchallRule& get_catch_all(const routing_handle_result& found) { std::vector bps_found; get_found_bp(found.blueprint_indices, blueprints_, bps_found); - for (int i = bps_found.size() - 1; i > 0; i--) - { - std::vector bpi = found.blueprint_indices; - if (bps_found[i]->catchall_rule().has_handler()) { - return bps_found[i]->catchall_rule(); + if (!bps_found.empty()) { + for (size_t i = bps_found.size() - 1; i > 0; i--) + { + if (bps_found[i]->catchall_rule().has_handler()) { + return bps_found[i]->catchall_rule(); + } } } return catchall_rule_; @@ -1544,20 +1546,17 @@ namespace crow // NOTE: Already documented in "crow/app.h" std::vector bps_found; get_found_bp(found.blueprint_indices, blueprints_, bps_found); - for (int i = bps_found.size() - 1; i > 0; i--) - { - std::vector bpi = found.blueprint_indices; - if (bps_found[i]->catchall_rule().has_handler()) - { + if (!bps_found.empty()) { + for (size_t i = bps_found.size() - 1; i > 0; i--) { + if (bps_found[i]->catchall_rule().has_handler()) { #ifdef CROW_ENABLE_DEBUG - return std::string("Redirected to Blueprint \"" + bps_found[i]->prefix() + "\" Catchall rule"); + return std::string("Redirected to Blueprint \"" + bps_found[i]->prefix() + "\" Catchall rule"); #else - return EMPTY; + return EMPTY; #endif + } } - } - if (catchall_rule_.has_handler()) - { + } else if (catchall_rule_.has_handler()) { #ifdef CROW_ENABLE_DEBUG return std::string("Redirected to global Catchall rule"); #else