diff --git a/include/fc/optional.hpp b/include/fc/optional.hpp index 04145b4..f79b7dc 100644 --- a/include/fc/optional.hpp +++ b/include/fc/optional.hpp @@ -1,6 +1,8 @@ #pragma once #include #include +#include + namespace fc { #ifdef _MSC_VER @@ -22,12 +24,13 @@ namespace fc { public: typedef T value_type; - optional():_valid(false){} + optional():_valid(false){ memset(_value, 0, sizeof(_value)); } ~optional(){ reset(); } optional( optional& o ) :_valid(false) { + memset(_value, 0, sizeof(_value)); if( o._valid ) new (ptr()) T( *o ); _valid = o._valid; } @@ -35,6 +38,7 @@ namespace fc { optional( const optional& o ) :_valid(false) { + memset(_value, 0, sizeof(_value)); if( o._valid ) new (ptr()) T( *o ); _valid = o._valid; } @@ -42,6 +46,7 @@ namespace fc { optional( optional&& o ) :_valid(false) { + memset(_value, 0, sizeof(_value)); if( o._valid ) new (ptr()) T( std::move(*o) ); _valid = o._valid; o.reset(); @@ -51,6 +56,7 @@ namespace fc { optional( const optional& o ) :_valid(false) { + memset(_value, 0, sizeof(_value)); if( o._valid ) new (ptr()) T( *o ); _valid = o._valid; } @@ -59,6 +65,7 @@ namespace fc { optional( optional& o ) :_valid(false) { + memset(_value, 0, sizeof(_value)); if( o._valid ) { new (ptr()) T( *o ); @@ -70,6 +77,7 @@ namespace fc { optional( optional&& o ) :_valid(false) { + memset(_value, 0, sizeof(_value)); if( o._valid ) new (ptr()) T( std::move(*o) ); _valid = o._valid; o.reset(); @@ -79,6 +87,7 @@ namespace fc { optional( U&& u ) :_valid(true) { + memset(_value, 0, sizeof(_value)); new ((char*)ptr()) T( std::forward(u) ); } diff --git a/src/compress/miniz.c b/src/compress/miniz.c index 987614d..f794c93 100644 --- a/src/compress/miniz.c +++ b/src/compress/miniz.c @@ -1497,7 +1497,10 @@ tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_nex { mz_uint8 *p = r->m_tables[0].m_code_size; mz_uint i; r->m_table_sizes[0] = 288; r->m_table_sizes[1] = 32; TINFL_MEMSET(r->m_tables[1].m_code_size, 5, 32); - for (i = 0; i <= 143; ++i) {*p++ = 8;} for (; i <= 255; ++i) {*p++ = 9;} for (; i <= 279; ++i) {*p++ = 7;} for (; i <= 287; ++i) {*p++ = 8;} + for ( i = 0; i <= 143; ++i) *p++ = 8; + for ( ; i <= 255; ++i) *p++ = 9; + for ( ; i <= 279; ++i) *p++ = 7; + for ( ; i <= 287; ++i) *p++ = 8; } else { @@ -2281,7 +2284,11 @@ static MZ_FORCEINLINE void tdefl_find_match(tdefl_compressor *d, mz_uint lookahe if (TDEFL_READ_UNALIGNED_WORD(&d->m_dict[probe_pos + match_len - 1]) == c01) break; TDEFL_PROBE; TDEFL_PROBE; TDEFL_PROBE; } - if (!dist) {break;} q = (const mz_uint16*)(d->m_dict + probe_pos); if (TDEFL_READ_UNALIGNED_WORD(q) != s01) {continue;} p = s; probe_len = 32; + if (!dist) break; + q = (const mz_uint16*)(d->m_dict + probe_pos); + if (TDEFL_READ_UNALIGNED_WORD(q) != s01) continue; + p = s; + probe_len = 32; do { } while ( (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (--probe_len > 0) ); if (!probe_len) diff --git a/src/crypto/aes.cpp b/src/crypto/aes.cpp index 55464a7..d675cc3 100644 --- a/src/crypto/aes.cpp +++ b/src/crypto/aes.cpp @@ -75,7 +75,9 @@ uint32_t aes_encoder::encode( const char* plaintxt, uint32_t plaintext_len, char FC_THROW_EXCEPTION( aes_exception, "error during aes 256 cbc encryption update", ("s", ERR_error_string( ERR_get_error(), nullptr) ) ); } - FC_ASSERT( (uint32_t) ciphertext_len == plaintext_len, "", ("ciphertext_len",ciphertext_len)("plaintext_len",plaintext_len) ); + int64_t ciphertext_len_i64 = ciphertext_len; + int64_t plaintext_len_i64 = plaintext_len; + FC_ASSERT( ciphertext_len_i64 == plaintext_len_i64, "", ("ciphertext_len",ciphertext_len)("plaintext_len",plaintext_len) ); return ciphertext_len; } #if 0 @@ -146,7 +148,9 @@ uint32_t aes_decoder::decode( const char* ciphertxt, uint32_t ciphertxt_len, cha FC_THROW_EXCEPTION( aes_exception, "error during aes 256 cbc decryption update", ("s", ERR_error_string( ERR_get_error(), nullptr) ) ); } - FC_ASSERT( ciphertxt_len == (uint32_t)plaintext_len, "", ("ciphertxt_len",ciphertxt_len)("plaintext_len",plaintext_len) ); + int64_t ciphertxt_len_i64 = ciphertxt_len; + int64_t plaintext_len_i64 = plaintext_len; + FC_ASSERT( ciphertxt_len_i64 == plaintext_len_i64, "", ("ciphertxt_len",ciphertxt_len)("plaintext_len",plaintext_len) ); return plaintext_len; } #if 0 diff --git a/src/crypto/elliptic_common.cpp b/src/crypto/elliptic_common.cpp index dc617c5..7e21bbd 100644 --- a/src/crypto/elliptic_common.cpp +++ b/src/crypto/elliptic_common.cpp @@ -83,8 +83,10 @@ namespace fc { namespace ecc { ssl_bignum order; FC_ASSERT( EC_GROUP_get_order( group, order, ctx ) ); private_key_secret bin; - FC_ASSERT( (size_t) BN_num_bytes( order ) == bin.data_size() ); - FC_ASSERT( (size_t) BN_bn2bin( order, (unsigned char*) bin.data() ) == bin.data_size() ); + size_t order_BN_num_bytes = BN_num_bytes( order ); + FC_ASSERT( order_BN_num_bytes == bin.data_size() ); + size_t order_BN_bn2bin = BN_bn2bin( order, (unsigned char*) bin.data() ); + FC_ASSERT( order_BN_bn2bin == bin.data_size() ); return bin; } @@ -102,8 +104,10 @@ namespace fc { namespace ecc { FC_ASSERT( EC_GROUP_get_order( group, order, ctx ) ); BN_rshift1( order, order ); private_key_secret bin; - FC_ASSERT( (size_t) BN_num_bytes( order ) == bin.data_size() ); - FC_ASSERT( (size_t) BN_bn2bin( order, (unsigned char*) bin.data() ) == bin.data_size() ); + size_t order_BN_num_bytes = BN_num_bytes( order ); + FC_ASSERT( order_BN_num_bytes == bin.data_size() ); + size_t order_BN_bn2bin = BN_bn2bin( order, (unsigned char*) bin.data() ); + FC_ASSERT( order_BN_bn2bin == bin.data_size() ); return bin; } diff --git a/src/crypto/ripemd160.cpp b/src/crypto/ripemd160.cpp index fe6c588..6838768 100644 --- a/src/crypto/ripemd160.cpp +++ b/src/crypto/ripemd160.cpp @@ -106,7 +106,9 @@ bool operator == ( const ripemd160& h1, const ripemd160& h2 ) { void from_variant( const variant& v, ripemd160& bi, uint32_t max_depth ) { std::vector ve = v.as< std::vector >( max_depth ); - memset( &bi, char(0), sizeof(bi) ); + for (size_t i = 0; i < bi.data_size(); i++) { + bi.data()[i] = 0; + } if( ve.size() ) memcpy( &bi, ve.data(), std::min(ve.size(),sizeof(bi)) ); } diff --git a/src/crypto/sha1.cpp b/src/crypto/sha1.cpp index d8337e5..49ad65f 100644 --- a/src/crypto/sha1.cpp +++ b/src/crypto/sha1.cpp @@ -90,7 +90,9 @@ bool operator == ( const sha1& h1, const sha1& h2 ) { void from_variant( const variant& v, sha1& bi, uint32_t max_depth ) { std::vector ve = v.as< std::vector >( max_depth ); - memset( &bi, char(0), sizeof(bi) ); + for (size_t i = 0; i < bi.data_size(); i++) { + bi.data()[i] = 0; + } if( ve.size() ) memcpy( &bi, ve.data(), std::min(ve.size(),sizeof(bi)) ); } diff --git a/src/crypto/sha224.cpp b/src/crypto/sha224.cpp index 54be117..d371963 100644 --- a/src/crypto/sha224.cpp +++ b/src/crypto/sha224.cpp @@ -86,7 +86,9 @@ namespace fc { void from_variant( const variant& v, sha224& bi, uint32_t max_depth ) { std::vector ve = v.as< std::vector >( max_depth ); - memset( &bi, char(0), sizeof(bi) ); + for (size_t i = 0; i < bi.data_size(); i++) { + bi.data()[i] = 0; + } if( ve.size() ) memcpy( &bi, ve.data(), std::min(ve.size(),sizeof(bi)) ); } diff --git a/src/crypto/sha256.cpp b/src/crypto/sha256.cpp index 6d35035..246f5e0 100644 --- a/src/crypto/sha256.cpp +++ b/src/crypto/sha256.cpp @@ -106,7 +106,9 @@ namespace fc { void from_variant( const variant& v, sha256& bi, uint32_t max_depth ) { std::vector ve = v.as< std::vector >( max_depth ); - memset( &bi, char(0), sizeof(bi) ); + for (size_t i = 0; i < bi.data_size(); i++) { + bi.data()[i] = 0; + } if( ve.size() ) memcpy( &bi, ve.data(), std::min(ve.size(),sizeof(bi)) ); } diff --git a/src/crypto/sha512.cpp b/src/crypto/sha512.cpp index d499314..2c44060 100644 --- a/src/crypto/sha512.cpp +++ b/src/crypto/sha512.cpp @@ -92,7 +92,9 @@ namespace fc { void from_variant( const variant& v, sha512& bi, uint32_t max_depth ) { std::vector ve = v.as< std::vector >( max_depth ); - memset( &bi, char(0), sizeof(bi) ); + for (size_t i = 0; i < bi.data_size(); i++) { + bi.data()[i] = 0; + } if( ve.size() ) memcpy( &bi, ve.data(), std::min(ve.size(),sizeof(bi)) ); }