1010#include < algorithm>
1111#include < type_traits>
1212#include < optional>
13+ #include < limits>
1314
1415#include " crow/common.h"
1516#include " crow/http_response.h"
@@ -721,7 +722,6 @@ namespace crow // NOTE: Already documented in "crow/app.h"
721722
722723 constexpr size_t RULE_SPECIAL_REDIRECT_SLASH = 1 ;
723724
724-
725725 // / A search tree.
726726 class Trie
727727 {
@@ -1317,7 +1317,9 @@ namespace crow // NOTE: Already documented in "crow/app.h"
13171317
13181318 ruleObject->foreach_method ([&](int method) {
13191319 per_methods_[method].rules .emplace_back (ruleObject);
1320- 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);
1320+ per_methods_[method].trie .add (rule, per_methods_[method].rules .size () - 1 ,
1321+ BP_index != INVALID_BP_ID ? blueprints[BP_index]->prefix ().length () : 0 ,
1322+ BP_index);
13211323
13221324 // directory case:
13231325 // request to '/about' url matches '/about/' rule
@@ -1528,11 +1530,12 @@ namespace crow // NOTE: Already documented in "crow/app.h"
15281530 CatchallRule& get_catch_all (const routing_handle_result& found) {
15291531 std::vector<Blueprint*> bps_found;
15301532 get_found_bp (found.blueprint_indices , blueprints_, bps_found);
1531- for (int i = bps_found.size () - 1 ; i > 0 ; i--)
1532- {
1533- std::vector<size_t > bpi = found.blueprint_indices ;
1534- if (bps_found[i]->catchall_rule ().has_handler ()) {
1535- return bps_found[i]->catchall_rule ();
1533+ if (!bps_found.empty ()) {
1534+ for (size_t i = bps_found.size () - 1 ; i > 0 ; i--)
1535+ {
1536+ if (bps_found[i]->catchall_rule ().has_handler ()) {
1537+ return bps_found[i]->catchall_rule ();
1538+ }
15361539 }
15371540 }
15381541 return catchall_rule_;
@@ -1544,20 +1547,17 @@ namespace crow // NOTE: Already documented in "crow/app.h"
15441547
15451548 std::vector<Blueprint*> bps_found;
15461549 get_found_bp (found.blueprint_indices , blueprints_, bps_found);
1547- for (int i = bps_found.size () - 1 ; i > 0 ; i--)
1548- {
1549- std::vector<size_t > bpi = found.blueprint_indices ;
1550- if (bps_found[i]->catchall_rule ().has_handler ())
1551- {
1550+ if (!bps_found.empty ()) {
1551+ for (size_t i = bps_found.size () - 1 ; i > 0 ; i--) {
1552+ if (bps_found[i]->catchall_rule ().has_handler ()) {
15521553#ifdef CROW_ENABLE_DEBUG
1553- return std::string (" Redirected to Blueprint \" " + bps_found[i]->prefix () + " \" Catchall rule" );
1554+ return std::string (" Redirected to Blueprint \" " + bps_found[i]->prefix () + " \" Catchall rule" );
15541555#else
1555- return EMPTY;
1556+ return EMPTY;
15561557#endif
1558+ }
15571559 }
1558- }
1559- if (catchall_rule_.has_handler ())
1560- {
1560+ } else if (catchall_rule_.has_handler ()) {
15611561#ifdef CROW_ENABLE_DEBUG
15621562 return std::string (" Redirected to global Catchall rule" );
15631563#else
0 commit comments