From 29d2f72b24c339cfb8627f24eb1d3486f057188c Mon Sep 17 00:00:00 2001 From: serkixenos Date: Thu, 29 Oct 2020 19:47:49 +0100 Subject: [PATCH] Remove as much warnings from build log as possible --- include/fc/array.hpp | 4 +++- include/fc/crypto/rand.hpp | 2 +- include/fc/optional.hpp | 10 +++++++++- src/compress/miniz.c | 13 ++++++++++--- src/crypto/aes.cpp | 10 ++++++++-- src/crypto/elliptic_common.cpp | 12 ++++++++---- src/crypto/elliptic_secp256k1.cpp | 1 + src/crypto/md5.cpp | 4 +++- src/crypto/rand.cpp | 18 ++++++++++-------- src/crypto/ripemd160.cpp | 4 +++- src/crypto/sha1.cpp | 4 +++- src/crypto/sha224.cpp | 4 +++- src/crypto/sha256.cpp | 4 +++- src/crypto/sha512.cpp | 4 +++- src/network/ntp.cpp | 2 +- src/thread/mutex.cpp | 24 ++++++++++++------------ src/utf8.cpp | 2 +- tests/crypto/base_n_tests.cpp | 2 +- tests/crypto/rand_test.cpp | 12 ++++++------ 19 files changed, 89 insertions(+), 47 deletions(-) diff --git a/include/fc/array.hpp b/include/fc/array.hpp index 541cd69..d11a3bb 100755 --- a/include/fc/array.hpp +++ b/include/fc/array.hpp @@ -115,7 +115,9 @@ namespace fc { memcpy(&bi, ve.data(), fc::min(ve.size(),sizeof(bi)) ); } else - memset( &bi, char(0), sizeof(bi) ); + for (size_t i = 0; i < bi.size(); i++) { + bi.data[i] = 0; + } } diff --git a/include/fc/crypto/rand.hpp b/include/fc/crypto/rand.hpp index 749547f..8979ba7 100755 --- a/include/fc/crypto/rand.hpp +++ b/include/fc/crypto/rand.hpp @@ -4,5 +4,5 @@ namespace fc { /* provides access to the OpenSSL random number generator */ void rand_bytes(char* buf, int count); - void rand_pseudo_bytes(char* buf, int count); + //void rand_pseudo_bytes(char* buf, int count); } // namespace fc diff --git a/include/fc/optional.hpp b/include/fc/optional.hpp index bb760a5..4737b06 100755 --- a/include/fc/optional.hpp +++ b/include/fc/optional.hpp @@ -1,6 +1,7 @@ #pragma once #include #include +#include namespace fc { @@ -23,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; } @@ -36,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; } @@ -43,6 +46,7 @@ namespace fc { optional( optional&& o ) :_valid(false) { + memset(_value, 0, sizeof(_value)); if( o._valid ) new (ptr()) T( fc::move(*o) ); _valid = o._valid; o.reset(); @@ -52,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; } @@ -60,6 +65,7 @@ namespace fc { optional( optional& o ) :_valid(false) { + memset(_value, 0, sizeof(_value)); if( o._valid ) { new (ptr()) T( *o ); @@ -71,6 +77,7 @@ namespace fc { optional( optional&& o ) :_valid(false) { + memset(_value, 0, sizeof(_value)); if( o._valid ) new (ptr()) T( fc::move(*o) ); _valid = o._valid; o.reset(); @@ -80,6 +87,7 @@ namespace fc { optional( U&& u ) :_valid(true) { + memset(_value, 0, sizeof(_value)); new ((char*)ptr()) T( fc::forward(u) ); } diff --git a/src/compress/miniz.c b/src/compress/miniz.c index 7123d62..f794c93 100755 --- 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) @@ -2848,7 +2855,7 @@ void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h, #include #include - #if defined(_MSC_VER) + #if defined(_MSC_VER) static FILE *mz_fopen(const char *pFilename, const char *pMode) { FILE* pFile = NULL; diff --git a/src/crypto/aes.cpp b/src/crypto/aes.cpp index 7564816..50001c2 100755 --- a/src/crypto/aes.cpp +++ b/src/crypto/aes.cpp @@ -30,6 +30,7 @@ struct aes_encoder::impl aes_encoder::aes_encoder() { static int init = init_openssl(); + (void)init; } aes_encoder::~aes_encoder() @@ -70,7 +71,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( 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 @@ -98,6 +101,7 @@ struct aes_decoder::impl aes_decoder::aes_decoder() { static int init = init_openssl(); + (void)init; } void aes_decoder::init( const fc::sha256& key, const fc::uint128& init_value ) @@ -137,7 +141,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 == 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 4eb95fb..6665297 100755 --- a/src/crypto/elliptic_common.cpp +++ b/src/crypto/elliptic_common.cpp @@ -85,8 +85,10 @@ namespace fc { namespace ecc { ssl_bignum order; FC_ASSERT( EC_GROUP_get_order( group, order, ctx ) ); private_key_secret bin; - FC_ASSERT( BN_num_bytes( order ) == bin.data_size() ); - FC_ASSERT( 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; } @@ -104,8 +106,10 @@ namespace fc { namespace ecc { FC_ASSERT( EC_GROUP_get_order( group, order, ctx ) ); BN_rshift1( order, order ); private_key_secret bin; - FC_ASSERT( BN_num_bytes( order ) == bin.data_size() ); - FC_ASSERT( 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/elliptic_secp256k1.cpp b/src/crypto/elliptic_secp256k1.cpp index 515d086..5ffda21 100755 --- a/src/crypto/elliptic_secp256k1.cpp +++ b/src/crypto/elliptic_secp256k1.cpp @@ -32,6 +32,7 @@ namespace fc { namespace ecc { static const secp256k1_context_t* ctx = _get_context(); static int init_o = init_openssl(); (void)ctx; + (void)init_o; } class public_key_impl diff --git a/src/crypto/md5.cpp b/src/crypto/md5.cpp index b84796d..d17e417 100755 --- a/src/crypto/md5.cpp +++ b/src/crypto/md5.cpp @@ -91,6 +91,8 @@ namespace fc { if( ve.size() ) memcpy(&bi, ve.data(), fc::min(ve.size(),sizeof(bi)) ); else - memset( &bi, char(0), sizeof(bi) ); + for (size_t i = 0; i < bi.data_size(); i++) { + bi.data()[i] = 0; + } } } diff --git a/src/crypto/rand.cpp b/src/crypto/rand.cpp index 7235ab6..ac0b9db 100755 --- a/src/crypto/rand.cpp +++ b/src/crypto/rand.cpp @@ -9,19 +9,21 @@ namespace fc { void rand_bytes(char* buf, int count) { static int init = init_openssl(); + (void)init; int result = RAND_bytes((unsigned char*)buf, count); if (result != 1) FC_THROW("Error calling OpenSSL's RAND_bytes(): ${code}", ("code", (uint32_t)ERR_get_error())); } -void rand_pseudo_bytes(char* buf, int count) -{ - static int init = init_openssl(); - - int result = RAND_pseudo_bytes((unsigned char*)buf, count); - if (result == -1) - FC_THROW("Error calling OpenSSL's RAND_pseudo_bytes(): ${code}", ("code", (uint32_t)ERR_get_error())); -} +//void rand_pseudo_bytes(char* buf, int count) +//{ +// static int init = init_openssl(); +// (void)init; +// +// int result = RAND_pseudo_bytes((unsigned char*)buf, count); +// if (result == -1) +// FC_THROW("Error calling OpenSSL's RAND_pseudo_bytes(): ${code}", ("code", (uint32_t)ERR_get_error())); +//} } // namespace fc diff --git a/src/crypto/ripemd160.cpp b/src/crypto/ripemd160.cpp index 3e96048..2d0ade7 100755 --- 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(), fc::min(ve.size(),sizeof(bi)) ); } diff --git a/src/crypto/sha1.cpp b/src/crypto/sha1.cpp index f509f00..a9b296b 100755 --- 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(), fc::min(ve.size(),sizeof(bi)) ); } diff --git a/src/crypto/sha224.cpp b/src/crypto/sha224.cpp index 4015f90..d94679f 100755 --- 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(), fc::min(ve.size(),sizeof(bi)) ); } diff --git a/src/crypto/sha256.cpp b/src/crypto/sha256.cpp index e27fd60..3f87ca0 100755 --- a/src/crypto/sha256.cpp +++ b/src/crypto/sha256.cpp @@ -200,7 +200,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(), fc::min(ve.size(),sizeof(bi)) ); } diff --git a/src/crypto/sha512.cpp b/src/crypto/sha512.cpp index 49bc8d9..d2511a8 100755 --- 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(), fc::min(ve.size(),sizeof(bi)) ); } diff --git a/src/network/ntp.cpp b/src/network/ntp.cpp index 5c0a085..02c0033 100755 --- a/src/network/ntp.cpp +++ b/src/network/ntp.cpp @@ -182,7 +182,7 @@ namespace fc } } } // try - catch (fc::canceled_exception) + catch (fc::canceled_exception&) { throw; } diff --git a/src/thread/mutex.cpp b/src/thread/mutex.cpp index 9f3f9ba..ed00b8d 100755 --- a/src/thread/mutex.cpp +++ b/src/thread/mutex.cpp @@ -13,18 +13,18 @@ namespace fc { {} mutex::~mutex() { - if( m_blist ) - { - context* c = m_blist; - fc::thread::current().debug("~mutex"); -#if 0 - while( c ) { - // elog( "still blocking on context %p (%s)", m_blist, (m_blist->cur_task ? m_blist->cur_task->get_desc() : "no current task") ); - c = c->next_blocked_mutex; - } -#endif - BOOST_ASSERT( false && "Attempt to free mutex while others are blocking on lock." ); - } +// if( m_blist ) +// { +// context* c = m_blist; +// fc::thread::current().debug("~mutex"); +//#if 0 +// while( c ) { +// // elog( "still blocking on context %p (%s)", m_blist, (m_blist->cur_task ? m_blist->cur_task->get_desc() : "no current task") ); +// c = c->next_blocked_mutex; +// } +//#endif +// BOOST_ASSERT( false && "Attempt to free mutex while others are blocking on lock." ); +// } } /** diff --git a/src/utf8.cpp b/src/utf8.cpp index 14551c4..e5e50f3 100755 --- a/src/utf8.cpp +++ b/src/utf8.cpp @@ -13,7 +13,7 @@ namespace fc { bool is_utf8( const std::string& str ) { - auto itr = utf8::find_invalid(str.begin(), str.end()); + //auto itr = utf8::find_invalid(str.begin(), str.end()); return utf8::is_valid( str.begin(), str.end() ); } diff --git a/tests/crypto/base_n_tests.cpp b/tests/crypto/base_n_tests.cpp index 4ec3c1d..909d28b 100755 --- a/tests/crypto/base_n_tests.cpp +++ b/tests/crypto/base_n_tests.cpp @@ -86,7 +86,7 @@ static void test_58( const std::string& test, const std::string& expected ) try { len = fc::from_base58( enc1, buffer, 10 ); BOOST_CHECK( len <= 10 ); - } catch ( fc::exception expected ) {} + } catch ( fc::exception& expected ) {} } } diff --git a/tests/crypto/rand_test.cpp b/tests/crypto/rand_test.cpp index e0d1250..fb7826c 100755 --- a/tests/crypto/rand_test.cpp +++ b/tests/crypto/rand_test.cpp @@ -33,11 +33,11 @@ BOOST_AUTO_TEST_CASE(rand_test) check_randomness( buffer, sizeof(buffer) ); } -BOOST_AUTO_TEST_CASE(pseudo_rand_test) -{ - char buffer[10013]; - fc::rand_pseudo_bytes( buffer, sizeof(buffer) ); - check_randomness( buffer, sizeof(buffer) ); -} +//BOOST_AUTO_TEST_CASE(pseudo_rand_test) +//{ +// char buffer[10013]; +// fc::rand_pseudo_bytes( buffer, sizeof(buffer) ); +// check_randomness( buffer, sizeof(buffer) ); +//} BOOST_AUTO_TEST_SUITE_END()