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

recast 64-bit size_t to 32-bit int to remove warnings #106

Merged
merged 4 commits into from
Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion include/crow/dumb_timer_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace crow
if (!self)
return;

unsigned int index = (unsigned int)(k.second - self->step_);
unsigned int index = static_cast<unsigned>(k.second - self->step_);
if (index < self->dq_.size())
self->dq_[index].second = nullptr;
}
Expand Down
4 changes: 2 additions & 2 deletions include/crow/http_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ namespace crow
res.is_alive_helper_ = [this]()->bool{ return adaptor_.is_open(); };

ctx_ = detail::context<Middlewares...>();
req.middleware_context = (void*)&ctx_;
req.middleware_context = static_cast<void*>(&ctx_);
req.io_service = &adaptor_.get_io_service();
detail::middleware_call_helper<0, decltype(ctx_), decltype(*middlewares_), Middlewares...>(*middlewares_, req, res, ctx_);

Expand Down Expand Up @@ -351,7 +351,7 @@ namespace crow

// call all after_handler of middlewares
detail::after_handlers_call_helper<
((int)sizeof...(Middlewares)-1),
(static_cast<int>(sizeof...(Middlewares))-1),
decltype(ctx_),
decltype(*middlewares_)>
(*middlewares_, ctx_, req_, res);
Expand Down
14 changes: 7 additions & 7 deletions include/crow/http_parser_merged.h
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ static const int8_t unhex[256] =
goto error;
}

parser->method = (enum http_method) 0;
parser->method = static_cast<http_method>(0);
parser->index = 1;
switch (ch) {
case 'C': parser->method = HTTP_CONNECT; /* or COPY, CHECKOUT */ break;
Expand Down Expand Up @@ -1357,7 +1357,7 @@ static const int8_t unhex[256] =
parser->state = s_req_server_start;
}

parser->state = parse_url_char((enum state)parser->state, ch);
parser->state = parse_url_char(static_cast<state>(parser->state), ch);
if (parser->state == s_dead) {
CROW_SET_ERRNO(HPE_INVALID_URL);
goto error;
Expand All @@ -1379,7 +1379,7 @@ static const int8_t unhex[256] =
CROW_SET_ERRNO(HPE_INVALID_URL);
goto error;
default:
parser->state = parse_url_char((enum state)parser->state, ch);
parser->state = parse_url_char(static_cast<state>(parser->state), ch);
if (parser->state == s_dead) {
CROW_SET_ERRNO(HPE_INVALID_URL);
goto error;
Expand Down Expand Up @@ -1412,7 +1412,7 @@ static const int8_t unhex[256] =
CROW_CALLBACK_DATA(url);
break;
default:
parser->state = parse_url_char((enum state)parser->state, ch);
parser->state = parse_url_char(static_cast<state>(parser->state), ch);
if (parser->state == s_dead) {
CROW_SET_ERRNO(HPE_INVALID_URL);
goto error;
Expand Down Expand Up @@ -2086,7 +2086,7 @@ static const int8_t unhex[256] =
assert(parser->nread == 1);
assert(parser->flags & F_CHUNKED);

unhex_val = unhex[(unsigned char)ch];
unhex_val = unhex[static_cast<unsigned char>(ch)];
if (unhex_val == -1) {
CROW_SET_ERRNO(HPE_INVALID_CHUNK_SIZE);
goto error;
Expand All @@ -2108,7 +2108,7 @@ static const int8_t unhex[256] =
break;
}

unhex_val = unhex[(unsigned char)ch];
unhex_val = unhex[static_cast<unsigned char>(ch)];

if (unhex_val == -1) {
if (ch == ';' || ch == ' ') {
Expand Down Expand Up @@ -2567,7 +2567,7 @@ http_parser_parse_url(const char *buf, size_t buflen, int is_connect,
return 1;
}

u->port = (uint16_t) v;
u->port = static_cast<uint16_t>(v);
}

return 0;
Expand Down
18 changes: 9 additions & 9 deletions include/crow/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ namespace crow
uint8_t owned_{0};
friend std::ostream& operator << (std::ostream& os, const r_string& s)
{
os << (std::string)s;
os << static_cast<std::string>(s);
return os;
}
private:
Expand Down Expand Up @@ -292,7 +292,7 @@ namespace crow

explicit operator int() const
{
return (int)i();
return static_cast<int>(i());
}

/// The type of the JSON value.
Expand Down Expand Up @@ -522,7 +522,7 @@ namespace crow
#ifndef CROW_JSON_NO_ERROR_CHECK
if (t() != type::List)
throw std::runtime_error("value is not a list");
if (index >= (int)lsize_ || index < 0)
if (index >= static_cast<int>(lsize_) || index < 0)
throw std::runtime_error("list out of bound");
#endif
return l_[index];
Expand Down Expand Up @@ -905,7 +905,7 @@ namespace crow
switch(*data)
{
case '0':
state = (NumberParsingState)"\2\2\7\3\4\6\6"[state];
state = static_cast<NumberParsingState>("\2\2\7\3\4\6\6"[state]);
/*if (state == NumberParsingState::Minus || state == NumberParsingState::AfterMinus)
{
state = NumberParsingState::ZeroFirst;
Expand All @@ -926,7 +926,7 @@ namespace crow
case '1': case '2': case '3':
case '4': case '5': case '6':
case '7': case '8': case '9':
state = (NumberParsingState)"\3\3\7\3\4\6\6"[state];
state = static_cast<NumberParsingState>("\3\3\7\3\4\6\6"[state]);
while(*(data+1) >= '0' && *(data+1) <= '9') data++;
/*if (state == NumberParsingState::Minus || state == NumberParsingState::AfterMinus)
{
Expand All @@ -946,7 +946,7 @@ namespace crow
return {};*/
break;
case '.':
state = (NumberParsingState)"\7\7\4\4\7\7\7"[state];
state = static_cast<NumberParsingState>("\7\7\4\4\7\7\7"[state]);
/*
if (state == NumberParsingState::Digits || state == NumberParsingState::ZeroFirst)
{
Expand All @@ -957,7 +957,7 @@ namespace crow
*/
break;
case '-':
state = (NumberParsingState)"\1\7\7\7\7\6\7"[state];
state = static_cast<NumberParsingState>("\1\7\7\7\7\6\7"[state]);
/*if (state == NumberParsingState::Minus)
{
state = NumberParsingState::AfterMinus;
Expand All @@ -970,7 +970,7 @@ namespace crow
return {};*/
break;
case '+':
state = (NumberParsingState)"\7\7\7\7\7\6\7"[state];
state = static_cast<NumberParsingState>("\7\7\7\7\7\6\7"[state]);
/*if (state == NumberParsingState::E)
{
state = NumberParsingState::DigitsAfterE;
Expand All @@ -979,7 +979,7 @@ namespace crow
return {};*/
break;
case 'e': case 'E':
state = (NumberParsingState)"\7\7\7\5\5\7\7"[state];
state = static_cast<NumberParsingState>("\7\7\7\5\5\7\7"[state]);
/*if (state == NumberParsingState::Digits ||
state == NumberParsingState::DigitsAfterPoints)
{
Expand Down
2 changes: 1 addition & 1 deletion include/crow/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ namespace crow
//
static LogLevel& get_log_level_ref()
{
static LogLevel current_level = (LogLevel)CROW_LOG_LEVEL;
static LogLevel current_level = static_cast<LogLevel>(CROW_LOG_LEVEL);
return current_level;
}
static ILogHandler*& get_handler_ref()
Expand Down
32 changes: 16 additions & 16 deletions include/crow/mustache.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ namespace crow
int end;
int pos;
ActionType t;
Action(ActionType t, int start, int end, int pos = 0)
: start(start), end(end), pos(pos), t(t)
Action(ActionType t, size_t start, size_t end, size_t pos = 0)
: start(static_cast<int>(start)), end(static_cast<int>(end)), pos(static_cast<int>(pos)), t(t)
{}
};

Expand Down Expand Up @@ -76,7 +76,7 @@ namespace crow
empty_str = "";

int dotPosition = name.find(".");
if (dotPosition == (int)name.npos)
if (dotPosition == static_cast<int>(name.npos))
{
for(auto it = stack.rbegin(); it != stack.rend(); ++it)
{
Expand All @@ -91,15 +91,15 @@ namespace crow
{
std::vector<int> dotPositions;
dotPositions.push_back(-1);
while(dotPosition != (int)name.npos)
while(dotPosition != static_cast<int>(name.npos))
{
dotPositions.push_back(dotPosition);
dotPosition = name.find(".", dotPosition+1);
}
dotPositions.push_back(name.size());
std::vector<std::string> names;
names.reserve(dotPositions.size()-1);
for(int i = 1; i < (int)dotPositions.size(); i ++)
for(int i = 1; i < static_cast<int>(dotPositions.size()); i ++)
names.emplace_back(name.substr(dotPositions[i-1]+1, dotPositions[i]-dotPositions[i-1]-1));

for(auto it = stack.rbegin(); it != stack.rend(); ++it)
Expand Down Expand Up @@ -216,7 +216,7 @@ namespace crow
out += ctx.s;
break;
default:
throw std::runtime_error("not implemented tag type" + boost::lexical_cast<std::string>((int)ctx.t()));
throw std::runtime_error("not implemented tag type" + boost::lexical_cast<std::string>(static_cast<int>(ctx.t())));
}
}
break;
Expand Down Expand Up @@ -282,7 +282,7 @@ namespace crow
current = action.pos;
break;
default:
throw std::runtime_error("{{#: not implemented context type: " + boost::lexical_cast<std::string>((int)ctx.t()));
throw std::runtime_error("{{#: not implemented context type: " + boost::lexical_cast<std::string>(static_cast<int>(ctx.t())));
break;
}
break;
Expand All @@ -291,7 +291,7 @@ namespace crow
stack.pop_back();
break;
default:
throw std::runtime_error("not implemented " + boost::lexical_cast<std::string>((int)action.t));
throw std::runtime_error("not implemented " + boost::lexical_cast<std::string>(static_cast<int>(action.t)));
}
current++;
}
Expand All @@ -305,7 +305,7 @@ namespace crow
for(int i = fragment.first; i < fragment.second; i ++)
{
out += body_[i];
if (body_[i] == '\n' && i+1 != (int)body_.size())
if (body_[i] == '\n' && i+1 != static_cast<int>(body_.size()))
out.insert(out.size(), indent, ' ');
}
}
Expand Down Expand Up @@ -348,11 +348,11 @@ namespace crow
size_t idx = body_.find(tag_open, current);
if (idx == body_.npos)
{
fragments_.emplace_back(current, body_.size());
fragments_.emplace_back(static_cast<int>(current), static_cast<int>(body_.size()));
actions_.emplace_back(ActionType::Ignore, 0, 0);
break;
}
fragments_.emplace_back(current, idx);
fragments_.emplace_back(static_cast<int>(current), static_cast<int>(idx));

idx += tag_open.size();
size_t endIdx = body_.find(tag_close, idx);
Expand All @@ -372,7 +372,7 @@ namespace crow
idx++;
while(body_[idx] == ' ') idx++;
while(body_[endIdx-1] == ' ') endIdx--;
blockPositions.emplace_back(actions_.size());
blockPositions.emplace_back(static_cast<int>(actions_.size()));
actions_.emplace_back(ActionType::OpenBlock, idx, endIdx);
break;
case '/':
Expand All @@ -397,7 +397,7 @@ namespace crow
idx++;
while(body_[idx] == ' ') idx++;
while(body_[endIdx-1] == ' ') endIdx--;
blockPositions.emplace_back(actions_.size());
blockPositions.emplace_back(static_cast<int>(actions_.size()));
actions_.emplace_back(ActionType::ElseBlock, idx, endIdx);
break;
case '!':
Expand Down Expand Up @@ -481,7 +481,7 @@ namespace crow
continue;
auto& fragment_before = fragments_[i];
auto& fragment_after = fragments_[i+1];
bool is_last_action = i == (int)actions_.size()-2;
bool is_last_action = i == static_cast<int>(actions_.size())-2;
bool all_space_before = true;
int j, k;
for(j = fragment_before.second-1;j >= fragment_before.first;j--)
Expand All @@ -497,7 +497,7 @@ namespace crow
if (!all_space_before && body_[j] != '\n')
continue;
bool all_space_after = true;
for(k = fragment_after.first; k < (int)body_.size() && k < fragment_after.second; k ++)
for(k = fragment_after.first; k < static_cast<int>(body_.size()) && k < fragment_after.second; k ++)
{
if (body_[k] != ' ')
{
Expand All @@ -512,7 +512,7 @@ namespace crow
body_[k] == '\n'
||
(body_[k] == '\r' &&
k + 1 < (int)body_.size() &&
k + 1 < static_cast<int>(body_.size()) &&
body_[k+1] == '\n')))
continue;
if (actions_[i].t == ActionType::Partial)
Expand Down
2 changes: 1 addition & 1 deletion include/crow/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ namespace crow
/// Take the parsed HTTP request data and convert it to a \ref crow.request
request to_request() const
{
return request{(HTTPMethod)method, std::move(raw_url), std::move(url), std::move(url_params), std::move(headers), std::move(body)};
return request{static_cast<HTTPMethod>(method), std::move(raw_url), std::move(url), std::move(url_params), std::move(headers), std::move(body)};
}

bool is_upgrade() const
Expand Down
12 changes: 6 additions & 6 deletions include/crow/query_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@ inline int qs_strncmp(const char * s, const char * qs, size_t n)

while(n-- > 0)
{
u1 = (unsigned char) *s++;
u2 = (unsigned char) *qs++;
u1 = static_cast<unsigned char>(*s++);
u2 = static_cast<unsigned char>(*qs++);

if ( ! CROW_QS_ISQSCHR(u1) ) { u1 = '\0'; }
if ( ! CROW_QS_ISQSCHR(u2) ) { u2 = '\0'; }

if ( u1 == '+' ) { u1 = ' '; }
if ( u1 == '%' ) // easier/safer than scanf
{
unyb = (unsigned char) *s++;
lnyb = (unsigned char) *s++;
unyb = static_cast<unsigned char>(*s++);
lnyb = static_cast<unsigned char>(*s++);
if ( CROW_QS_ISHEX(unyb) && CROW_QS_ISHEX(lnyb) )
u1 = (CROW_QS_HEX2DEC(unyb) * 16) + CROW_QS_HEX2DEC(lnyb);
else
Expand All @@ -75,8 +75,8 @@ inline int qs_strncmp(const char * s, const char * qs, size_t n)
if ( u2 == '+' ) { u2 = ' '; }
if ( u2 == '%' ) // easier/safer than scanf
{
unyb = (unsigned char) *qs++;
lnyb = (unsigned char) *qs++;
unyb = static_cast<unsigned char>(*qs++);
lnyb = static_cast<unsigned char>(*qs++);
if ( CROW_QS_ISHEX(unyb) && CROW_QS_ISHEX(lnyb) )
u2 = (CROW_QS_HEX2DEC(unyb) * 16) + CROW_QS_HEX2DEC(lnyb);
else
Expand Down
Loading