adds a bunch of explicit casts where signedness or truncation occurs references #218

This commit is contained in:
Peter Thorson
2013-05-01 08:24:02 -05:00
parent 0905b7d4e9
commit 24774fc124
10 changed files with 33 additions and 27 deletions

View File

@@ -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

View File

@@ -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 );

View File

@@ -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<std::string::value_type>(char_array_3[j]);
}
}
return ret;

View File

@@ -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<size_t*>(input);
size_t* output_word = reinterpret_cast<size_t*>(output);
size_t * input_word = reinterpret_cast<size_t *>(input);
size_t * output_word = reinterpret_cast<size_t *>(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<char *>(&prepared_key);
uint8_t * byte_key = reinterpret_cast<uint8_t *>(&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);

View File

@@ -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<unsigned char>(*(begin+2))))
{
it+=3;
}

View File

@@ -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<int>(nbytes));
std::memcpy(pms->buf + offset, p, copy);
if (offset + copy < 64)

View File

@@ -67,7 +67,7 @@ public:
explicit hybi00(bool secure, bool server, msg_manager_ptr manager)
: processor<config>(secure, server)
, msg_hdr(0x00)
, msg_ftr(reinterpret_cast<char>(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<size_t>(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<const char*>(&msg_hdr),1));
// process payload
out->set_payload(i);
out->append_payload(std::string(&msg_ftr,1));
out->append_payload(std::string(reinterpret_cast<const char*>(&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<uint32_t>(strtoul(digits.c_str(), NULL, 10));
if (spaces > 0 && num > 0) {
num = htonl(num/spaces);
std::copy(reinterpret_cast<char*>(&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;

View File

@@ -326,14 +326,14 @@ private:
break;
}
in.read(m_buf+m_cursor,m_len-m_cursor);
in.read(m_buf+m_cursor,static_cast<std::streamsize>(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<size_t>(in.gcount());
// TODO: error handling
if (in.bad()) {

View File

@@ -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<unsigned int>(atoi(port.c_str()));
if (t_port > 65535) {
throw websocketpp::uri_exception("Port must be less than 65535");

View File

@@ -55,7 +55,7 @@ public:
template <typename iterator_type>
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<uint8_t>(*i)) == UTF8_REJECT) {
return false;
}
}