Skip to content

Commit 9b8bd14

Browse files
Fix Routing's methods_ Bitmask Overflow (#1169)
* Methods have more than 32 values which means we can't use a 32 bit value to represent it use 64 bit values for bit mask now
1 parent 0e9aa2e commit 9b8bd14

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

include/crow/routing.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,15 @@ namespace crow // NOTE: Already documented in "crow/app.h"
135135
}
136136
#endif
137137

138-
uint32_t get_methods()
138+
uint64_t get_methods()
139139
{
140140
return methods_;
141141
}
142142

143143
template<typename F>
144144
void foreach_method(F f)
145145
{
146-
for (uint32_t method = 0, method_bit = 1; method < static_cast<uint32_t>(HTTPMethod::InternalMethodCount); method++, method_bit <<= 1)
146+
for (uint64_t method = 0, method_bit = 1; method < static_cast<uint64_t>(HTTPMethod::InternalMethodCount); method++, method_bit <<= 1)
147147
{
148148
if (methods_ & method_bit)
149149
f(method);
@@ -155,7 +155,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
155155
const std::string& rule() { return rule_; }
156156

157157
protected:
158-
uint32_t methods_{1 << static_cast<int>(HTTPMethod::Get)};
158+
uint64_t methods_{1ULL << static_cast<int>(HTTPMethod::Get)};
159159

160160
std::string rule_;
161161
std::string name_;
@@ -566,15 +566,15 @@ namespace crow // NOTE: Already documented in "crow/app.h"
566566

567567
self_t& methods(HTTPMethod method)
568568
{
569-
static_cast<self_t*>(this)->methods_ = 1 << static_cast<int>(method);
569+
static_cast<self_t*>(this)->methods_ = 1ULL << static_cast<int>(method);
570570
return static_cast<self_t&>(*this);
571571
}
572572

573573
template<typename... MethodArgs>
574574
self_t& methods(HTTPMethod method, MethodArgs... args_method)
575575
{
576576
methods(args_method...);
577-
static_cast<self_t*>(this)->methods_ |= 1 << static_cast<int>(method);
577+
static_cast<self_t*>(this)->methods_ |= 1ULL << static_cast<int>(method);
578578
return static_cast<self_t&>(*this);
579579
}
580580

@@ -1470,7 +1470,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
14701470
}
14711471

14721472
CROW_LOG_DEBUG << "Matched rule (upgrade) '" << rules[rule_index]->rule_ << "' "
1473-
<< static_cast<uint32_t>(req.method) << " / "
1473+
<< static_cast<uint64_t>(req.method) << " / "
14741474
<< rules[rule_index]->get_methods();
14751475

14761476
try
@@ -1725,7 +1725,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
17251725
res.add_header("Location", req.url + "/");
17261726
res.end();
17271727
} else {
1728-
CROW_LOG_DEBUG << "Matched rule '" << rules[rule_index]->rule_ << "' " << static_cast<uint32_t>(req.
1728+
CROW_LOG_DEBUG << "Matched rule '" << rules[rule_index]->rule_ << "' " << static_cast<uint64_t>(req.
17291729
method) << " / " << rules[rule_index]->get_methods();
17301730

17311731
try {

0 commit comments

Comments
 (0)