From b55e9bca0c747154aeeb188df9a8a6eda6d65124 Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Wed, 27 Apr 2016 11:53:30 -0700 Subject: Change calls to 'get_byte' to explicitly cast parameters and eliminate compiler warnings --- src/lib/modes/aead/ccm/ccm.cpp | 4 ++-- src/lib/tls/msg_certificate.cpp | 4 ++-- src/lib/tls/tls_channel.cpp | 4 ++-- src/lib/tls/tls_extensions.cpp | 24 ++++++++++++------------ src/lib/tls/tls_handshake_io.cpp | 6 +++--- src/lib/tls/tls_record.cpp | 12 ++++++------ src/lib/utils/loadstor.h | 2 +- 7 files changed, 28 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/lib/modes/aead/ccm/ccm.cpp b/src/lib/modes/aead/ccm/ccm.cpp index df33685f3..1f528769e 100644 --- a/src/lib/modes/aead/ccm/ccm.cpp +++ b/src/lib/modes/aead/ccm/ccm.cpp @@ -81,8 +81,8 @@ void CCM_Mode::set_associated_data(const byte ad[], size_t length) // FIXME: support larger AD using length encoding rules BOTAN_ASSERT(length < (0xFFFF - 0xFF), "Supported CCM AD length"); - m_ad_buf.push_back(get_byte(0, length)); - m_ad_buf.push_back(get_byte(1, length)); + m_ad_buf.push_back(get_byte(0, static_cast(length))); + m_ad_buf.push_back(get_byte(1, static_cast(length))); m_ad_buf += std::make_pair(ad, length); while(m_ad_buf.size() % BS) m_ad_buf.push_back(0); // pad with zeros to full block size diff --git a/src/lib/tls/msg_certificate.cpp b/src/lib/tls/msg_certificate.cpp index 5be9379bd..32e3e17f0 100644 --- a/src/lib/tls/msg_certificate.cpp +++ b/src/lib/tls/msg_certificate.cpp @@ -73,14 +73,14 @@ std::vector Certificate::serialize() const const size_t cert_size = raw_cert.size(); for(size_t j = 0; j != 3; ++j) { - buf.push_back(get_byte(j+1, cert_size)); + buf.push_back(get_byte(j+1, static_cast(cert_size))); } buf += raw_cert; } const size_t buf_size = buf.size() - 3; for(size_t i = 0; i != 3; ++i) - buf[i] = get_byte(i+1, buf_size); + buf[i] = get_byte(i+1, static_cast(buf_size)); return buf; } diff --git a/src/lib/tls/tls_channel.cpp b/src/lib/tls/tls_channel.cpp index 2cf351c80..131196ce5 100644 --- a/src/lib/tls/tls_channel.cpp +++ b/src/lib/tls/tls_channel.cpp @@ -630,8 +630,8 @@ SymmetricKey Channel::key_material_export(const std::string& label, size_t context_size = context.length(); if(context_size > 0xFFFF) throw Exception("key_material_export context is too long"); - salt.push_back(get_byte(0, context_size)); - salt.push_back(get_byte(1, context_size)); + salt.push_back(get_byte(0, static_cast(context_size))); + salt.push_back(get_byte(1, static_cast(context_size))); salt += to_byte_vector(context); } diff --git a/src/lib/tls/tls_extensions.cpp b/src/lib/tls/tls_extensions.cpp index 8befb2fbc..fc442ab14 100644 --- a/src/lib/tls/tls_extensions.cpp +++ b/src/lib/tls/tls_extensions.cpp @@ -99,8 +99,8 @@ std::vector Extensions::serialize() const buf.push_back(get_byte(0, extn_code)); buf.push_back(get_byte(1, extn_code)); - buf.push_back(get_byte(0, extn_val.size())); - buf.push_back(get_byte(1, extn_val.size())); + buf.push_back(get_byte(0, static_cast(extn_val.size()))); + buf.push_back(get_byte(1, static_cast(extn_val.size()))); buf += extn_val; } @@ -163,12 +163,12 @@ std::vector Server_Name_Indicator::serialize() const size_t name_len = m_sni_host_name.size(); - buf.push_back(get_byte(0, name_len+3)); - buf.push_back(get_byte(1, name_len+3)); + buf.push_back(get_byte(0, static_cast(name_len+3))); + buf.push_back(get_byte(1, static_cast(name_len+3))); buf.push_back(0); // DNS - buf.push_back(get_byte(0, name_len)); - buf.push_back(get_byte(1, name_len)); + buf.push_back(get_byte(0, static_cast(name_len))); + buf.push_back(get_byte(1, static_cast(name_len))); buf += std::make_pair( reinterpret_cast(m_sni_host_name.data()), @@ -264,8 +264,8 @@ std::vector Application_Layer_Protocol_Notification::serialize() const 1); } - buf[0] = get_byte(0, buf.size()-2); - buf[1] = get_byte(1, buf.size()-2); + buf[0] = get_byte(0, static_cast(buf.size()-2)); + buf[1] = get_byte(1, static_cast(buf.size()-2)); return buf; } @@ -320,8 +320,8 @@ std::vector Supported_Elliptic_Curves::serialize() const buf.push_back(get_byte(1, id)); } - buf[0] = get_byte(0, buf.size()-2); - buf[1] = get_byte(1, buf.size()-2); + buf[0] = get_byte(0, static_cast(buf.size()-2)); + buf[1] = get_byte(1, static_cast(buf.size()-2)); return buf; } @@ -435,8 +435,8 @@ std::vector Signature_Algorithms::serialize() const {} } - buf[0] = get_byte(0, buf.size()-2); - buf[1] = get_byte(1, buf.size()-2); + buf[0] = get_byte(0, static_cast(buf.size()-2)); + buf[1] = get_byte(1, static_cast(buf.size()-2)); return buf; } diff --git a/src/lib/tls/tls_handshake_io.cpp b/src/lib/tls/tls_handshake_io.cpp index f39c9f84e..720e4459f 100644 --- a/src/lib/tls/tls_handshake_io.cpp +++ b/src/lib/tls/tls_handshake_io.cpp @@ -28,9 +28,9 @@ inline size_t load_be24(const byte q[3]) void store_be24(byte out[3], size_t val) { - out[0] = get_byte(1, val); - out[1] = get_byte(2, val); - out[2] = get_byte(3, val); + out[0] = get_byte(1, static_cast(val)); + out[1] = get_byte(2, static_cast(val)); + out[2] = get_byte(3, static_cast(val)); } u64bit steady_clock_ms() diff --git a/src/lib/tls/tls_record.cpp b/src/lib/tls/tls_record.cpp index 8af6587e3..16ba42ce6 100644 --- a/src/lib/tls/tls_record.cpp +++ b/src/lib/tls/tls_record.cpp @@ -172,8 +172,8 @@ void write_record(secure_vector& output, if(!cs) // initial unencrypted handshake records { - output.push_back(get_byte(0, msg_length)); - output.push_back(get_byte(1, msg_length)); + output.push_back(get_byte(0, static_cast(msg_length))); + output.push_back(get_byte(1, static_cast(msg_length))); output.insert(output.end(), msg, msg + msg_length); @@ -190,8 +190,8 @@ void write_record(secure_vector& output, const size_t rec_size = ctext_size + cs->nonce_bytes_from_record(); BOTAN_ASSERT(rec_size <= 0xFFFF, "Ciphertext length fits in field"); - output.push_back(get_byte(0, rec_size)); - output.push_back(get_byte(1, rec_size)); + output.push_back(get_byte(0, static_cast(rec_size))); + output.push_back(get_byte(1, static_cast(rec_size))); aead->set_ad(cs->format_ad(seq, msg_type, version, msg_length)); @@ -228,8 +228,8 @@ void write_record(secure_vector& output, if(buf_size > MAX_CIPHERTEXT_SIZE) throw Internal_Error("Output record is larger than allowed by protocol"); - output.push_back(get_byte(0, buf_size)); - output.push_back(get_byte(1, buf_size)); + output.push_back(get_byte(0, static_cast(buf_size))); + output.push_back(get_byte(1, static_cast(buf_size))); const size_t header_size = output.size(); diff --git a/src/lib/utils/loadstor.h b/src/lib/utils/loadstor.h index a6c2b7969..9ae9fda0e 100644 --- a/src/lib/utils/loadstor.h +++ b/src/lib/utils/loadstor.h @@ -47,7 +47,7 @@ namespace Botan { template inline byte get_byte(size_t byte_num, T input) { return static_cast( - input >> ((sizeof(T)-1-(byte_num&(sizeof(T)-1))) << 3) + input >> (((~byte_num)&(sizeof(T)-1)) << 3) ); } -- cgit v1.2.3