diff --git a/include/crow/dumb_timer_queue.h b/include/crow/dumb_timer_queue.h index 1b4544fdc..8b48662b5 100644 --- a/include/crow/dumb_timer_queue.h +++ b/include/crow/dumb_timer_queue.h @@ -27,7 +27,7 @@ namespace crow if (!self) return; - unsigned int index = (unsigned int)(k.second - self->step_); + unsigned int index = static_cast(k.second - self->step_); if (index < self->dq_.size()) self->dq_[index].second = nullptr; } diff --git a/include/crow/http_connection.h b/include/crow/http_connection.h index 62d8a91eb..2fd51a7d7 100644 --- a/include/crow/http_connection.h +++ b/include/crow/http_connection.h @@ -317,7 +317,7 @@ namespace crow res.is_alive_helper_ = [this]()->bool{ return adaptor_.is_open(); }; ctx_ = detail::context(); - req.middleware_context = (void*)&ctx_; + req.middleware_context = static_cast(&ctx_); req.io_service = &adaptor_.get_io_service(); detail::middleware_call_helper<0, decltype(ctx_), decltype(*middlewares_), Middlewares...>(*middlewares_, req, res, ctx_); @@ -351,7 +351,7 @@ namespace crow // call all after_handler of middlewares detail::after_handlers_call_helper< - ((int)sizeof...(Middlewares)-1), + (static_cast(sizeof...(Middlewares))-1), decltype(ctx_), decltype(*middlewares_)> (*middlewares_, ctx_, req_, res); diff --git a/include/crow/http_parser_merged.h b/include/crow/http_parser_merged.h index 09f5ebcfb..d0ee6cebf 100644 --- a/include/crow/http_parser_merged.h +++ b/include/crow/http_parser_merged.h @@ -1234,7 +1234,7 @@ static const int8_t unhex[256] = goto error; } - parser->method = (enum http_method) 0; + parser->method = static_cast(0); parser->index = 1; switch (ch) { case 'C': parser->method = HTTP_CONNECT; /* or COPY, CHECKOUT */ break; @@ -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(parser->state), ch); if (parser->state == s_dead) { CROW_SET_ERRNO(HPE_INVALID_URL); goto error; @@ -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(parser->state), ch); if (parser->state == s_dead) { CROW_SET_ERRNO(HPE_INVALID_URL); goto error; @@ -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(parser->state), ch); if (parser->state == s_dead) { CROW_SET_ERRNO(HPE_INVALID_URL); goto error; @@ -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(ch)]; if (unhex_val == -1) { CROW_SET_ERRNO(HPE_INVALID_CHUNK_SIZE); goto error; @@ -2108,7 +2108,7 @@ static const int8_t unhex[256] = break; } - unhex_val = unhex[(unsigned char)ch]; + unhex_val = unhex[static_cast(ch)]; if (unhex_val == -1) { if (ch == ';' || ch == ' ') { @@ -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(v); } return 0; diff --git a/include/crow/json.h b/include/crow/json.h index f3ace745f..5af288167 100644 --- a/include/crow/json.h +++ b/include/crow/json.h @@ -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(s); return os; } private: @@ -292,7 +292,7 @@ namespace crow explicit operator int() const { - return (int)i(); + return static_cast(i()); } /// The type of the JSON value. @@ -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(lsize_) || index < 0) throw std::runtime_error("list out of bound"); #endif return l_[index]; @@ -905,7 +905,7 @@ namespace crow switch(*data) { case '0': - state = (NumberParsingState)"\2\2\7\3\4\6\6"[state]; + state = static_cast("\2\2\7\3\4\6\6"[state]); /*if (state == NumberParsingState::Minus || state == NumberParsingState::AfterMinus) { state = NumberParsingState::ZeroFirst; @@ -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("\3\3\7\3\4\6\6"[state]); while(*(data+1) >= '0' && *(data+1) <= '9') data++; /*if (state == NumberParsingState::Minus || state == NumberParsingState::AfterMinus) { @@ -946,7 +946,7 @@ namespace crow return {};*/ break; case '.': - state = (NumberParsingState)"\7\7\4\4\7\7\7"[state]; + state = static_cast("\7\7\4\4\7\7\7"[state]); /* if (state == NumberParsingState::Digits || state == NumberParsingState::ZeroFirst) { @@ -957,7 +957,7 @@ namespace crow */ break; case '-': - state = (NumberParsingState)"\1\7\7\7\7\6\7"[state]; + state = static_cast("\1\7\7\7\7\6\7"[state]); /*if (state == NumberParsingState::Minus) { state = NumberParsingState::AfterMinus; @@ -970,7 +970,7 @@ namespace crow return {};*/ break; case '+': - state = (NumberParsingState)"\7\7\7\7\7\6\7"[state]; + state = static_cast("\7\7\7\7\7\6\7"[state]); /*if (state == NumberParsingState::E) { state = NumberParsingState::DigitsAfterE; @@ -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("\7\7\7\5\5\7\7"[state]); /*if (state == NumberParsingState::Digits || state == NumberParsingState::DigitsAfterPoints) { diff --git a/include/crow/logging.h b/include/crow/logging.h index 2ad61f4e6..b8a00d221 100644 --- a/include/crow/logging.h +++ b/include/crow/logging.h @@ -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(CROW_LOG_LEVEL); return current_level; } static ILogHandler*& get_handler_ref() diff --git a/include/crow/mustache.h b/include/crow/mustache.h index d39be113f..5be8db737 100644 --- a/include/crow/mustache.h +++ b/include/crow/mustache.h @@ -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(start)), end(static_cast(end)), pos(static_cast(pos)), t(t) {} }; @@ -76,7 +76,7 @@ namespace crow empty_str = ""; int dotPosition = name.find("."); - if (dotPosition == (int)name.npos) + if (dotPosition == static_cast(name.npos)) { for(auto it = stack.rbegin(); it != stack.rend(); ++it) { @@ -91,7 +91,7 @@ namespace crow { std::vector dotPositions; dotPositions.push_back(-1); - while(dotPosition != (int)name.npos) + while(dotPosition != static_cast(name.npos)) { dotPositions.push_back(dotPosition); dotPosition = name.find(".", dotPosition+1); @@ -99,7 +99,7 @@ namespace crow dotPositions.push_back(name.size()); std::vector names; names.reserve(dotPositions.size()-1); - for(int i = 1; i < (int)dotPositions.size(); i ++) + for(int i = 1; i < static_cast(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) @@ -216,7 +216,7 @@ namespace crow out += ctx.s; break; default: - throw std::runtime_error("not implemented tag type" + boost::lexical_cast((int)ctx.t())); + throw std::runtime_error("not implemented tag type" + boost::lexical_cast(static_cast(ctx.t()))); } } break; @@ -282,7 +282,7 @@ namespace crow current = action.pos; break; default: - throw std::runtime_error("{{#: not implemented context type: " + boost::lexical_cast((int)ctx.t())); + throw std::runtime_error("{{#: not implemented context type: " + boost::lexical_cast(static_cast(ctx.t()))); break; } break; @@ -291,7 +291,7 @@ namespace crow stack.pop_back(); break; default: - throw std::runtime_error("not implemented " + boost::lexical_cast((int)action.t)); + throw std::runtime_error("not implemented " + boost::lexical_cast(static_cast(action.t))); } current++; } @@ -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(body_.size())) out.insert(out.size(), indent, ' '); } } @@ -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(current), static_cast(body_.size())); actions_.emplace_back(ActionType::Ignore, 0, 0); break; } - fragments_.emplace_back(current, idx); + fragments_.emplace_back(static_cast(current), static_cast(idx)); idx += tag_open.size(); size_t endIdx = body_.find(tag_close, idx); @@ -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(actions_.size())); actions_.emplace_back(ActionType::OpenBlock, idx, endIdx); break; case '/': @@ -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(actions_.size())); actions_.emplace_back(ActionType::ElseBlock, idx, endIdx); break; case '!': @@ -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(actions_.size())-2; bool all_space_before = true; int j, k; for(j = fragment_before.second-1;j >= fragment_before.first;j--) @@ -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(body_.size()) && k < fragment_after.second; k ++) { if (body_[k] != ' ') { @@ -512,7 +512,7 @@ namespace crow body_[k] == '\n' || (body_[k] == '\r' && - k + 1 < (int)body_.size() && + k + 1 < static_cast(body_.size()) && body_[k+1] == '\n'))) continue; if (actions_[i].t == ActionType::Partial) diff --git a/include/crow/parser.h b/include/crow/parser.h index aa3e56201..dd96ac7bb 100644 --- a/include/crow/parser.h +++ b/include/crow/parser.h @@ -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(method), std::move(raw_url), std::move(url), std::move(url_params), std::move(headers), std::move(body)}; } bool is_upgrade() const diff --git a/include/crow/query_string.h b/include/crow/query_string.h index c3931a4bf..f299ce3a0 100644 --- a/include/crow/query_string.h +++ b/include/crow/query_string.h @@ -55,8 +55,8 @@ 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(*s++); + u2 = static_cast(*qs++); if ( ! CROW_QS_ISQSCHR(u1) ) { u1 = '\0'; } if ( ! CROW_QS_ISQSCHR(u2) ) { u2 = '\0'; } @@ -64,8 +64,8 @@ inline int qs_strncmp(const char * s, const char * qs, size_t n) if ( u1 == '+' ) { u1 = ' '; } if ( u1 == '%' ) // easier/safer than scanf { - unyb = (unsigned char) *s++; - lnyb = (unsigned char) *s++; + unyb = static_cast(*s++); + lnyb = static_cast(*s++); if ( CROW_QS_ISHEX(unyb) && CROW_QS_ISHEX(lnyb) ) u1 = (CROW_QS_HEX2DEC(unyb) * 16) + CROW_QS_HEX2DEC(lnyb); else @@ -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(*qs++); + lnyb = static_cast(*qs++); if ( CROW_QS_ISHEX(unyb) && CROW_QS_ISHEX(lnyb) ) u2 = (CROW_QS_HEX2DEC(unyb) * 16) + CROW_QS_HEX2DEC(lnyb); else diff --git a/include/crow/routing.h b/include/crow/routing.h index 7a8eaded1..d80c779fb 100644 --- a/include/crow/routing.h +++ b/include/crow/routing.h @@ -63,7 +63,7 @@ namespace crow template void foreach_method(F f) { - for(uint32_t method = 0, method_bit = 1; method < (uint32_t)HTTPMethod::InternalMethodCount; method++, method_bit<<=1) + for(uint32_t method = 0, method_bit = 1; method < static_cast(HTTPMethod::InternalMethodCount); method++, method_bit<<=1) { if (methods_ & method_bit) f(method); @@ -73,7 +73,7 @@ namespace crow const std::string& rule() { return rule_; } protected: - uint32_t methods_{1<<(int)HTTPMethod::Get}; + uint32_t methods_{1<(HTTPMethod::Get)}; std::string rule_; std::string name_; @@ -357,29 +357,29 @@ namespace crow using self_t = T; WebSocketRule& websocket() { - auto p =new WebSocketRule(((self_t*)this)->rule_); - ((self_t*)this)->rule_to_upgrade_.reset(p); + auto p =new WebSocketRule(static_cast(this)->rule_); + static_cast(this)->rule_to_upgrade_.reset(p); return *p; } self_t& name(std::string name) noexcept { - ((self_t*)this)->name_ = std::move(name); - return (self_t&)*this; + static_cast(this)->name_ = std::move(name); + return static_cast(*this); } self_t& methods(HTTPMethod method) { - ((self_t*)this)->methods_ = 1 << (int)method; - return (self_t&)*this; + static_cast(this)->methods_ = 1 << static_cast(method); + return static_cast(*this); } template self_t& methods(HTTPMethod method, MethodArgs ... args_method) { methods(args_method...); - ((self_t*)this)->methods_ |= 1 << (int)method; - return (self_t&)*this; + static_cast(this)->methods_ |= 1 << static_cast(method); + return static_cast(*this); } }; @@ -606,7 +606,7 @@ namespace crow struct Node { unsigned rule_index{}; - std::array param_childrens{}; + std::array(ParamType::MAX)> param_childrens{}; std::unordered_map children; bool IsSimpleNode() const @@ -706,7 +706,7 @@ public: } }; - if (node->param_childrens[(int)ParamType::INT]) + if (node->param_childrens[static_cast(ParamType::INT)]) { char c = req_url[pos]; if ((c >= '0' && c <= '9') || c == '+' || c == '-') @@ -717,14 +717,14 @@ public: if (errno != ERANGE && eptr != req_url.data()+pos) { params->int_params.push_back(value); - auto ret = find(req_url, &nodes_[node->param_childrens[(int)ParamType::INT]], eptr - req_url.data(), params); + auto ret = find(req_url, &nodes_[node->param_childrens[static_cast(ParamType::INT)]], eptr - req_url.data(), params); update_found(ret); params->int_params.pop_back(); } } } - if (node->param_childrens[(int)ParamType::UINT]) + if (node->param_childrens[static_cast(ParamType::UINT)]) { char c = req_url[pos]; if ((c >= '0' && c <= '9') || c == '+') @@ -735,14 +735,14 @@ public: if (errno != ERANGE && eptr != req_url.data()+pos) { params->uint_params.push_back(value); - auto ret = find(req_url, &nodes_[node->param_childrens[(int)ParamType::UINT]], eptr - req_url.data(), params); + auto ret = find(req_url, &nodes_[node->param_childrens[static_cast(ParamType::UINT)]], eptr - req_url.data(), params); update_found(ret); params->uint_params.pop_back(); } } } - if (node->param_childrens[(int)ParamType::DOUBLE]) + if (node->param_childrens[static_cast(ParamType::DOUBLE)]) { char c = req_url[pos]; if ((c >= '0' && c <= '9') || c == '+' || c == '-' || c == '.') @@ -753,14 +753,14 @@ public: if (errno != ERANGE && eptr != req_url.data()+pos) { params->double_params.push_back(value); - auto ret = find(req_url, &nodes_[node->param_childrens[(int)ParamType::DOUBLE]], eptr - req_url.data(), params); + auto ret = find(req_url, &nodes_[node->param_childrens[static_cast(ParamType::DOUBLE)]], eptr - req_url.data(), params); update_found(ret); params->double_params.pop_back(); } } } - if (node->param_childrens[(int)ParamType::STRING]) + if (node->param_childrens[static_cast(ParamType::STRING)]) { size_t epos = pos; for(; epos < req_url.size(); epos ++) @@ -772,20 +772,20 @@ public: if (epos != pos) { params->string_params.push_back(req_url.substr(pos, epos-pos)); - auto ret = find(req_url, &nodes_[node->param_childrens[(int)ParamType::STRING]], epos, params); + auto ret = find(req_url, &nodes_[node->param_childrens[static_cast(ParamType::STRING)]], epos, params); update_found(ret); params->string_params.pop_back(); } } - if (node->param_childrens[(int)ParamType::PATH]) + if (node->param_childrens[static_cast(ParamType::PATH)]) { size_t epos = req_url.size(); if (epos != pos) { params->string_params.push_back(req_url.substr(pos, epos-pos)); - auto ret = find(req_url, &nodes_[node->param_childrens[(int)ParamType::PATH]], epos, params); + auto ret = find(req_url, &nodes_[node->param_childrens[static_cast(ParamType::PATH)]], epos, params); update_found(ret); params->string_params.pop_back(); } @@ -834,12 +834,12 @@ public: { if (url.compare(i, x.name.size(), x.name) == 0) { - if (!nodes_[idx].param_childrens[(int)x.type]) + if (!nodes_[idx].param_childrens[static_cast(x.type)]) { auto new_node_idx = new_node(); - nodes_[idx].param_childrens[(int)x.type] = new_node_idx; + nodes_[idx].param_childrens[static_cast(x.type)] = new_node_idx; } - idx = nodes_[idx].param_childrens[(int)x.type]; + idx = nodes_[idx].param_childrens[static_cast(x.type)]; i += x.name.size(); break; } @@ -865,12 +865,12 @@ public: private: void debug_node_print(Node* n, int level) { - for(int i = 0; i < (int)ParamType::MAX; i ++) + for(int i = 0; i < static_cast(ParamType::MAX); i ++) { if (n->param_childrens[i]) { CROW_LOG_DEBUG << std::string(2*level, ' ') /*<< "("<param_childrens[i]<<") "*/; - switch((ParamType)i) + switch(static_cast(i)) { case ParamType::INT: CROW_LOG_DEBUG << ""; @@ -1006,7 +1006,7 @@ public: if (req.method >= HTTPMethod::InternalMethodCount) return; - auto& per_method = per_methods_[(int)req.method]; + auto& per_method = per_methods_[static_cast(req.method)]; auto& rules = per_method.rules; unsigned rule_index = per_method.trie.find(req.url).first; @@ -1050,7 +1050,7 @@ public: return; } - CROW_LOG_DEBUG << "Matched rule (upgrade) '" << rules[rule_index]->rule_ << "' " << (uint32_t)req.method << " / " << rules[rule_index]->get_methods(); + CROW_LOG_DEBUG << "Matched rule (upgrade) '" << rules[rule_index]->rule_ << "' " << static_cast(req.method) << " / " << rules[rule_index]->get_methods(); // any uncaught exceptions become 500s try @@ -1077,7 +1077,7 @@ public: { if (req.method >= HTTPMethod::InternalMethodCount) return; - auto& per_method = per_methods_[(int)req.method]; + auto& per_method = per_methods_[static_cast(req.method)]; auto& trie = per_method.trie; auto& rules = per_method.rules; @@ -1125,7 +1125,7 @@ public: return; } - CROW_LOG_DEBUG << "Matched rule '" << rules[rule_index]->rule_ << "' " << (uint32_t)req.method << " / " << rules[rule_index]->get_methods(); + CROW_LOG_DEBUG << "Matched rule '" << rules[rule_index]->rule_ << "' " << static_cast(req.method) << " / " << rules[rule_index]->get_methods(); // any uncaught exceptions become 500s try @@ -1150,9 +1150,9 @@ public: void debug_print() { - for(int i = 0; i < (int)HTTPMethod::InternalMethodCount; i ++) + for(int i = 0; i < static_cast(HTTPMethod::InternalMethodCount); i ++) { - CROW_LOG_DEBUG << method_name((HTTPMethod)i); + CROW_LOG_DEBUG << method_name(static_cast(i)); per_methods_[i].trie.debug_print(); } } @@ -1166,7 +1166,7 @@ public: // rule index 0, 1 has special meaning; preallocate it to avoid duplication. PerMethod() : rules(2) {} }; - std::array per_methods_; + std::array(HTTPMethod::InternalMethodCount)> per_methods_; std::vector> all_rules_; }; } diff --git a/include/crow/utility.h b/include/crow/utility.h index 0e6d2af53..5b2991bb4 100644 --- a/include/crow/utility.h +++ b/include/crow/utility.h @@ -510,29 +510,29 @@ template auto it = ret.begin(); while(size >= 3) { - *it++ = key[(((unsigned char)*data)&0xFC)>>2]; - unsigned char h = (((unsigned char)*data++) & 0x03) << 4; - *it++ = key[h|((((unsigned char)*data)&0xF0)>>4)]; - h = (((unsigned char)*data++) & 0x0F) << 2; - *it++ = key[h|((((unsigned char)*data)&0xC0)>>6)]; - *it++ = key[((unsigned char)*data++)&0x3F]; + *it++ = key[(static_cast(*data)&0xFC)>>2]; + unsigned char h = (static_cast(*data++) & 0x03) << 4; + *it++ = key[h|((static_cast(*data)&0xF0)>>4)]; + h = (static_cast(*data++) & 0x0F) << 2; + *it++ = key[h|((static_cast(*data)&0xC0)>>6)]; + *it++ = key[static_cast(*data++)&0x3F]; size -= 3; } if (size == 1) { - *it++ = key[(((unsigned char)*data)&0xFC)>>2]; - unsigned char h = (((unsigned char)*data++) & 0x03) << 4; + *it++ = key[(static_cast(*data)&0xFC)>>2]; + unsigned char h = (static_cast(*data++) & 0x03) << 4; *it++ = key[h]; *it++ = '='; *it++ = '='; } else if (size == 2) { - *it++ = key[(((unsigned char)*data)&0xFC)>>2]; - unsigned char h = (((unsigned char)*data++) & 0x03) << 4; - *it++ = key[h|((((unsigned char)*data)&0xF0)>>4)]; - h = (((unsigned char)*data++) & 0x0F) << 2; + *it++ = key[(static_cast(*data)&0xFC)>>2]; + unsigned char h = (static_cast(*data++) & 0x03) << 4; + *it++ = key[h|((static_cast(*data)&0xF0)>>4)]; + h = (static_cast(*data++) & 0x0F) << 2; *it++ = key[h]; *it++ = '='; } diff --git a/include/crow/websocket.h b/include/crow/websocket.h index f55173828..6b2d4e73d 100644 --- a/include/crow/websocket.h +++ b/include/crow/websocket.h @@ -200,7 +200,7 @@ namespace crow else if (size < 0x10000) { buf[1] += 126; - *(uint16_t*)(buf+2) = htons((uint16_t)size); + *(uint16_t*)(buf+2) = htons(static_cast(size)); return {buf, buf+4}; } else @@ -344,7 +344,7 @@ namespace crow ) { is_reading = false; - remaining_length_ = ((1==ntohl(1)) ? (remaining_length_) : ((uint64_t)ntohl((remaining_length_) & 0xFFFFFFFF) << 32) | ntohl((remaining_length_) >> 32)); + remaining_length_ = ((1==ntohl(1)) ? (remaining_length_) : (static_cast(ntohl((remaining_length_) & 0xFFFFFFFF)) << 32) | ntohl((remaining_length_) >> 32)); #ifdef CROW_ENABLE_DEBUG if (!ec && bytes_transferred != 8) {