diff --git a/SConstruct b/SConstruct index 5f63f55490..96026a449f 100644 --- a/SConstruct +++ b/SConstruct @@ -88,10 +88,12 @@ else: # Compiler specific warning flags if env['CXX'].startswith('g++'): + #env.Append(CCFLAGS = ['-Wconversion']) env.Append(CCFLAGS = ['-Wcast-align']) elif env['CXX'].startswith('clang++'): #env.Append(CCFLAGS = ['-Wcast-align']) #env.Append(CCFLAGS = ['-Wglobal-constructors']) + #env.Append(CCFLAGS = ['-Wconversion']) env.Append(CCFLAGS = ['-Wno-padded']) # Wpadded diff --git a/test/utility/close.cpp b/test/utility/close.cpp index 44d89e577a..6d4881534b 100644 --- a/test/utility/close.cpp +++ b/test/utility/close.cpp @@ -65,25 +65,25 @@ BOOST_AUTO_TEST_CASE( value_extraction ) { // Value = 1000 payload[0] = 0x03; - payload[1] = 0xe8; + payload[1] = char(0xe8); BOOST_CHECK( close::extract_code(payload,ec) == close::status::normal ); BOOST_CHECK( !ec ); // Value = 1004 payload[0] = 0x03; - payload[1] = 0xec; + payload[1] = char(0xec); BOOST_CHECK( close::extract_code(payload,ec) == 1004 ); BOOST_CHECK( ec == error::reserved_close_code ); // Value = 1005 payload[0] = 0x03; - payload[1] = 0xed; + payload[1] = char(0xed); BOOST_CHECK( close::extract_code(payload,ec) == close::status::no_status ); BOOST_CHECK( ec == error::invalid_close_code ); // Value = 3000 payload[0] = 0x0b; - payload[1] = 0xb8; + payload[1] = char(0xb8); BOOST_CHECK( close::extract_code(payload,ec) == 3000 ); BOOST_CHECK( !ec ); } @@ -120,7 +120,7 @@ BOOST_AUTO_TEST_CASE( extract_reason ) { BOOST_CHECK( !ec ); payload = "000"; - payload[2] = 0xFF; + payload[2] = char(0xFF); close::extract_reason(payload,ec); BOOST_CHECK( ec == error::invalid_utf8 ); diff --git a/websocketpp/base64/base64.hpp b/websocketpp/base64/base64.hpp index 7f60955714..ec4b3ad88f 100644 --- a/websocketpp/base64/base64.hpp +++ b/websocketpp/base64/base64.hpp @@ -137,7 +137,9 @@ inline std::string base64_decode(std::string const& encoded_string) { char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; - for (j = 0; (j < i - 1); j++) ret += char_array_3[j]; + for (j = 0; (j < i - 1); j++) { + ret += static_cast(char_array_3[j]); + } } return ret; diff --git a/websocketpp/frame.hpp b/websocketpp/frame.hpp index f8e0d06037..8bad56f5c4 100644 --- a/websocketpp/frame.hpp +++ b/websocketpp/frame.hpp @@ -198,7 +198,7 @@ struct extended_header { copy_payload(payload_size); } - extended_header(uint64_t payload_size, int32_t masking_key) { + extended_header(uint64_t payload_size, uint32_t masking_key) { std::fill_n(this->bytes,MAX_EXTENDED_HEADER_LENGTH,0x00); // Copy payload size @@ -740,13 +740,13 @@ inline void word_mask_exact(uint8_t* data, size_t length, const * * @return the prepared_key shifted to account for the input length */ -inline size_t word_mask_circ(uint8_t* input, uint8_t* output, size_t length, +inline size_t word_mask_circ(uint8_t * input, uint8_t * output, size_t length, size_t prepared_key) { size_t n = length / sizeof(size_t); // whole words size_t l = length - (n * sizeof(size_t)); // remaining bytes - size_t* input_word = reinterpret_cast(input); - size_t* output_word = reinterpret_cast(output); + size_t * input_word = reinterpret_cast(input); + size_t * output_word = reinterpret_cast(output); // mask word by word for (size_t i = 0; i < n; i++) { @@ -755,9 +755,9 @@ inline size_t word_mask_circ(uint8_t* input, uint8_t* output, size_t length, // mask partial word at the end size_t start = length - l; - char * test = reinterpret_cast(&prepared_key); + uint8_t * byte_key = reinterpret_cast(&prepared_key); for (size_t i = 0; i < l; ++i) { - output[start+i] = input[start+i] ^ test[i]; + output[start+i] = input[start+i] ^ byte_key[i]; } return circshift_prepared_key(prepared_key,l); diff --git a/websocketpp/http/parser.hpp b/websocketpp/http/parser.hpp index 646e650366..0f2ae321d9 100644 --- a/websocketpp/http/parser.hpp +++ b/websocketpp/http/parser.hpp @@ -104,7 +104,9 @@ InputIterator extract_lws(InputIterator begin, InputIterator end) { InputIterator it = begin; // strip leading CRLF - if (end-begin > 2 && *begin == '\r' && *(begin+1) == '\n' && is_whitespace_char(*(begin+2))) { + if (end-begin > 2 && *begin == '\r' && *(begin+1) == '\n' && + is_whitespace_char(static_cast(*(begin+2)))) + { it+=3; } diff --git a/websocketpp/md5/md5.hpp b/websocketpp/md5/md5.hpp index 14636103d2..b06a2be82b 100644 --- a/websocketpp/md5/md5.hpp +++ b/websocketpp/md5/md5.hpp @@ -374,7 +374,7 @@ md5_append(md5_state_t *pms, const md5_byte_t *data, size_t nbytes) /* Process an initial partial block. */ if (offset) { - int copy = (offset + nbytes > 64 ? 64 - offset : nbytes); + int copy = (offset + nbytes > 64 ? 64 - offset : static_cast(nbytes)); std::memcpy(pms->buf + offset, p, copy); if (offset + copy < 64) diff --git a/websocketpp/processors/hybi00.hpp b/websocketpp/processors/hybi00.hpp index 227f1c5b9e..b4cf6b0cb5 100644 --- a/websocketpp/processors/hybi00.hpp +++ b/websocketpp/processors/hybi00.hpp @@ -67,7 +67,7 @@ public: explicit hybi00(bool secure, bool server, msg_manager_ptr manager) : processor(secure, server) , msg_hdr(0x00) - , msg_ftr(reinterpret_cast(0xff)) + , msg_ftr(0xff) , m_state(HEADER) , m_msg_manager(manager) {} @@ -232,13 +232,13 @@ public: m_state = FATAL_ERROR; } } else if (m_state == PAYLOAD) { - uint8_t *it = std::find(buf+p,buf+len,uint8_t(msg_ftr)); + uint8_t *it = std::find(buf+p,buf+len,msg_ftr); // 0 1 2 3 4 5 // 0x00 0x23 0x23 0x23 0xff 0xXX // Copy payload bytes into message - l = it-(buf+p); + l = static_cast(it-(buf+p)); m_msg_ptr->append_payload(buf+p,l); p += l; @@ -307,11 +307,11 @@ public: } // generate header - out->set_header(std::string(&msg_hdr,1)); + out->set_header(std::string(reinterpret_cast(&msg_hdr),1)); // process payload out->set_payload(i); - out->append_payload(std::string(&msg_ftr,1)); + out->append_payload(std::string(reinterpret_cast(&msg_ftr),1)); // hybi00 doesn't support compression // hybi00 doesn't have masking @@ -338,7 +338,7 @@ public: } private: void decode_client_key(const std::string& key, char* result) const { - int spaces = 0; + unsigned int spaces = 0; std::string digits = ""; uint32_t num; @@ -351,7 +351,7 @@ private: } } - num = strtoul(digits.c_str(), NULL, 10); + num = static_cast(strtoul(digits.c_str(), NULL, 10)); if (spaces > 0 && num > 0) { num = htonl(num/spaces); std::copy(reinterpret_cast(&num), @@ -369,8 +369,8 @@ private: FATAL_ERROR = 3 }; - const char msg_hdr; - const char msg_ftr; + const uint8_t msg_hdr; + const uint8_t msg_ftr; state m_state; diff --git a/websocketpp/transport/iostream/connection.hpp b/websocketpp/transport/iostream/connection.hpp index 03e7fc4b27..6bb94426dc 100644 --- a/websocketpp/transport/iostream/connection.hpp +++ b/websocketpp/transport/iostream/connection.hpp @@ -326,14 +326,14 @@ private: break; } - in.read(m_buf+m_cursor,m_len-m_cursor); + in.read(m_buf+m_cursor,static_cast(m_len-m_cursor)); if (in.gcount() == 0) { m_elog.write(log::elevel::devel,"read zero bytes"); break; } - m_cursor += in.gcount(); + m_cursor += static_cast(in.gcount()); // TODO: error handling if (in.bad()) { diff --git a/websocketpp/uri.hpp b/websocketpp/uri.hpp index 14ca9cd0de..c14dbcebd7 100644 --- a/websocketpp/uri.hpp +++ b/websocketpp/uri.hpp @@ -255,7 +255,7 @@ private: return (m_secure ? uri_default_secure_port : uri_default_port); } - unsigned int t_port = atoi(port.c_str()); + unsigned int t_port = static_cast(atoi(port.c_str())); if (t_port > 65535) { throw websocketpp::uri_exception("Port must be less than 65535"); diff --git a/websocketpp/utf8_validator.hpp b/websocketpp/utf8_validator.hpp index 43cbea0de8..58b3391628 100644 --- a/websocketpp/utf8_validator.hpp +++ b/websocketpp/utf8_validator.hpp @@ -55,7 +55,7 @@ public: template bool decode (iterator_type b, iterator_type e) { for (iterator_type i = b; i != e; i++) { - if (utf8_validator::decode(&m_state,&m_codepoint,*i) == UTF8_REJECT) { + if (utf8_validator::decode(&m_state,&m_codepoint,static_cast(*i)) == UTF8_REJECT) { return false; } }