From 5138c58e0905430f4bff39a774f6d04b2d0bc150 Mon Sep 17 00:00:00 2001 From: Alexey Frolov Date: Fri, 2 Feb 2018 15:29:46 +0300 Subject: [PATCH] sanitize, remove warnings --- include/fc/io/json_relaxed.hpp | 2 ++ include/fc/static_variant.hpp | 7 +++--- include/fc/thread/thread.hpp | 1 + src/asio.cpp | 8 +++++++ src/compress/miniz.c | 6 ++--- src/crypto/aes.cpp | 12 +++++----- src/crypto/base36.cpp | 5 +++- src/crypto/base58.cpp | 4 +++- src/crypto/elliptic_common.cpp | 8 +++---- src/crypto/elliptic_secp256k1.cpp | 5 ++-- src/crypto/rand.cpp | 4 ++-- src/rpc/cli.cpp | 6 ++--- src/thread/mutex.cpp | 2 +- src/thread/thread.cpp | 20 ++++++++++------ src/utf8.cpp | 1 - tests/bloom_test.cpp | 2 +- tests/crypto/base_n_tests.cpp | 13 ++++------ tests/crypto/blowfish_test.cpp | 34 +++++++++++++-------------- tests/crypto/rand_test.cpp | 4 +++- tests/crypto/sha_tests.cpp | 2 +- tests/hmac_test.cpp | 2 +- tests/network/http/websocket_test.cpp | 6 ++--- tests/real128_test.cpp | 10 ++++---- 23 files changed, 91 insertions(+), 73 deletions(-) diff --git a/include/fc/io/json_relaxed.hpp b/include/fc/io/json_relaxed.hpp index e4876f2..c1a0966 100644 --- a/include/fc/io/json_relaxed.hpp +++ b/include/fc/io/json_relaxed.hpp @@ -231,6 +231,8 @@ namespace fc { namespace json_relaxed } } FC_RETHROW_EXCEPTIONS( warn, "while parsing string" ); + + return {}; } struct CharValueTable diff --git a/include/fc/static_variant.hpp b/include/fc/static_variant.hpp index 688d4b9..4f13f5b 100644 --- a/include/fc/static_variant.hpp +++ b/include/fc/static_variant.hpp @@ -181,7 +181,7 @@ class static_variant { static_assert(impl::type_info::no_reference_types, "Reference types are not permitted in static_variant."); static_assert(impl::type_info::no_duplicates, "static_variant type arguments contain duplicate types."); - int _tag; + size_t _tag; char storage[impl::type_info::size]; template @@ -326,15 +326,14 @@ public: } static int count() { return impl::type_info::count; } - void set_which( int w ) { - FC_ASSERT( w >= 0 ); + void set_which( size_t w ) { FC_ASSERT( w < count() ); this->~static_variant(); _tag = w; impl::storage_ops<0, Types...>::con(_tag, storage); } - int which() const {return _tag;} + size_t which() const {return _tag;} }; template diff --git a/include/fc/thread/thread.hpp b/include/fc/thread/thread.hpp index bb82710..aea55da 100644 --- a/include/fc/thread/thread.hpp +++ b/include/fc/thread/thread.hpp @@ -32,6 +32,7 @@ namespace fc { an existing "unknown" boost thread). In such cases, thread_d doesn't have access boost::thread object. */ static thread& current(); + static void cleanup(); /** diff --git a/src/asio.cpp b/src/asio.cpp index 0169576..1313ed7 100644 --- a/src/asio.cpp +++ b/src/asio.cpp @@ -3,6 +3,7 @@ #include #include #include +#include namespace fc { namespace asio { @@ -104,6 +105,13 @@ namespace fc { asio_threads.push_back( new boost::thread( [=]() { fc::thread::current().set_name("asio"); + + BOOST_SCOPE_EXIT(void) + { + fc::thread::cleanup(); + } + BOOST_SCOPE_EXIT_END + while (!io->stopped()) { try diff --git a/src/compress/miniz.c b/src/compress/miniz.c index 7123d62..987614d 100644 --- a/src/compress/miniz.c +++ b/src/compress/miniz.c @@ -1497,7 +1497,7 @@ 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 +2281,7 @@ 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 +2848,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..09db92b 100644 --- a/src/crypto/aes.cpp +++ b/src/crypto/aes.cpp @@ -29,7 +29,7 @@ struct aes_encoder::impl aes_encoder::aes_encoder() { - static int init = init_openssl(); + static __attribute__((unused)) int init = init_openssl(); } aes_encoder::~aes_encoder() @@ -70,7 +70,7 @@ 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) ); + FC_ASSERT( (uint32_t) ciphertext_len == plaintext_len, "", ("ciphertext_len",ciphertext_len)("plaintext_len",plaintext_len) ); return ciphertext_len; } #if 0 @@ -96,9 +96,9 @@ struct aes_decoder::impl }; aes_decoder::aes_decoder() - { - static int init = init_openssl(); - } +{ + static __attribute__((unused)) int init = init_openssl(); +} void aes_decoder::init( const fc::sha256& key, const fc::uint128& init_value ) { @@ -137,7 +137,7 @@ 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) ); + FC_ASSERT( ciphertxt_len == (uint32_t)plaintext_len, "", ("ciphertxt_len",ciphertxt_len)("plaintext_len",plaintext_len) ); return plaintext_len; } #if 0 diff --git a/src/crypto/base36.cpp b/src/crypto/base36.cpp index d0685ae..5e3bd5b 100644 --- a/src/crypto/base36.cpp +++ b/src/crypto/base36.cpp @@ -76,7 +76,10 @@ namespace fc while (len > 0 && *first == 0) { first++; len--; } std::vector result; result.resize(leading_zeros + len, 0); - memcpy( result.data() + leading_zeros, first, len ); + if (len) + { + memcpy( result.data() + leading_zeros, first, len ); + } return result; } } diff --git a/src/crypto/base58.cpp b/src/crypto/base58.cpp index e1d5d33..4551678 100644 --- a/src/crypto/base58.cpp +++ b/src/crypto/base58.cpp @@ -632,7 +632,9 @@ size_t from_base58( const std::string& base58_str, char* out_data, size_t out_da FC_THROW_EXCEPTION( parse_error_exception, "Unable to decode base58 string ${base58_str}", ("base58_str",base58_str) ); } FC_ASSERT( out.size() <= out_data_len ); - memcpy( out_data, out.data(), out.size() ); + if (!out.empty()) { + memcpy( out_data, out.data(), out.size() ); + } return out.size(); } } diff --git a/src/crypto/elliptic_common.cpp b/src/crypto/elliptic_common.cpp index 66b75d0..9b9044c 100644 --- a/src/crypto/elliptic_common.cpp +++ b/src/crypto/elliptic_common.cpp @@ -85,8 +85,8 @@ 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() ); + 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() ); return bin; } @@ -104,8 +104,8 @@ 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() ); + 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() ); return bin; } diff --git a/src/crypto/elliptic_secp256k1.cpp b/src/crypto/elliptic_secp256k1.cpp index 91edc18..469cc1b 100644 --- a/src/crypto/elliptic_secp256k1.cpp +++ b/src/crypto/elliptic_secp256k1.cpp @@ -29,9 +29,8 @@ namespace fc { namespace ecc { } void _init_lib() { - static const secp256k1_context_t* ctx = _get_context(); - static int init_o = init_openssl(); - (void)ctx; + static __attribute__((unused)) const secp256k1_context_t* ctx = _get_context(); + static __attribute__((unused)) int init_o = init_openssl(); } class public_key_impl diff --git a/src/crypto/rand.cpp b/src/crypto/rand.cpp index 7235ab6..2b194c5 100644 --- a/src/crypto/rand.cpp +++ b/src/crypto/rand.cpp @@ -8,7 +8,7 @@ namespace fc { void rand_bytes(char* buf, int count) { - static int init = init_openssl(); + static __attribute__((unused)) int init = init_openssl(); int result = RAND_bytes((unsigned char*)buf, count); if (result != 1) @@ -17,7 +17,7 @@ void rand_bytes(char* buf, int count) void rand_pseudo_bytes(char* buf, int count) { - static int init = init_openssl(); + static __attribute__((unused)) int init = init_openssl(); int result = RAND_pseudo_bytes((unsigned char*)buf, count); if (result == -1) diff --git a/src/rpc/cli.cpp b/src/rpc/cli.cpp index d3070fb..e59d4bb 100644 --- a/src/rpc/cli.cpp +++ b/src/rpc/cli.cpp @@ -136,7 +136,7 @@ char * dupstr (const char* s) { char* my_generator(const char* text, int state) { - static int list_index, len; + static size_t list_index, len; const char *name; if (!state) { @@ -160,20 +160,20 @@ char* my_generator(const char* text, int state) } +#ifdef HAVE_READLINE static char** cli_completion( const char * text , int start, int end) { char **matches; matches = (char **)NULL; -#ifdef HAVE_READLINE if (start == 0) matches = rl_completion_matches ((char*)text, &my_generator); else rl_bind_key('\t',rl_abort); -#endif return (matches); } +#endif void cli::getline( const fc::string& prompt, fc::string& line) diff --git a/src/thread/mutex.cpp b/src/thread/mutex.cpp index 9f3f9ba..2a87564 100644 --- a/src/thread/mutex.cpp +++ b/src/thread/mutex.cpp @@ -15,7 +15,7 @@ namespace fc { mutex::~mutex() { if( m_blist ) { - context* c = m_blist; +// context* c = m_blist; fc::thread::current().debug("~mutex"); #if 0 while( c ) { diff --git a/src/thread/thread.cpp b/src/thread/thread.cpp index 7b899bb..7ca01f2 100644 --- a/src/thread/thread.cpp +++ b/src/thread/thread.cpp @@ -113,8 +113,10 @@ namespace fc { if( my ) { // wlog( "calling quit() on ${n}",("n",my->name) ); - quit(); // deletes `my` + quit(); } + + delete my; } thread& thread::current() { @@ -123,6 +125,11 @@ namespace fc { return *current_thread(); } + void thread::cleanup() { + delete current_thread(); + current_thread() = nullptr; + } + const string& thread::name()const { return my->name; @@ -152,19 +159,18 @@ namespace fc { { //if quitting from a different thread, start quit task on thread. //If we have and know our attached boost thread, wait for it to finish, then return. - if( ¤t() != this ) + if( !is_current() ) { + auto t = my->boost_thread; async( [=](){quit();}, "thread::quit" );//.wait(); - if( my->boost_thread ) + if( t ) { //wlog("destroying boost thread ${tid}",("tid",(uintptr_t)my->boost_thread->native_handle())); - my->boost_thread->join(); - delete my; - my = nullptr; + t->join(); } return; } - + my->done = true; // wlog( "${s}", ("s",name()) ); // We are quiting from our own thread... diff --git a/src/utf8.cpp b/src/utf8.cpp index 14551c4..d98cd87 100644 --- a/src/utf8.cpp +++ b/src/utf8.cpp @@ -13,7 +13,6 @@ namespace fc { bool is_utf8( const std::string& str ) { - auto itr = utf8::find_invalid(str.begin(), str.end()); return utf8::is_valid( str.begin(), str.end() ); } diff --git a/tests/bloom_test.cpp b/tests/bloom_test.cpp index ca17792..1ba7e0d 100644 --- a/tests/bloom_test.cpp +++ b/tests/bloom_test.cpp @@ -48,7 +48,7 @@ BOOST_AUTO_TEST_CASE(bloom_test_1) std::string line; std::ifstream in("README.md"); std::ofstream words("words.txt"); - while( !in.eof() && count < 100000 ) + while( in.good() && count < 100000 ) { std::getline(in, line); // std::cout << "'"< 10) { @@ -53,7 +53,7 @@ static void test_36( const std::string& test, const std::string& expected ) std::vector dec = fc::from_base36( enc1 ); BOOST_CHECK_EQUAL( vec.size(), dec.size() ); - BOOST_CHECK( !memcmp( vec.data(), dec.data(), vec.size() ) ); + BOOST_CHECK( vec == dec ); } BOOST_AUTO_TEST_CASE(base36_test) @@ -76,17 +76,14 @@ static void test_58( const std::string& test, const std::string& expected ) std::vector dec = fc::from_base58( enc1 ); BOOST_CHECK_EQUAL( vec.size(), dec.size() ); - BOOST_CHECK( !memcmp( vec.data(), dec.data(), vec.size() ) ); + BOOST_CHECK( vec == dec ); char buffer[64]; size_t len = fc::from_base58( enc1, buffer, 64 ); BOOST_CHECK( len <= 64 ); - BOOST_CHECK( !memcmp( vec.data(), buffer, len ) ); + BOOST_CHECK( vec.empty() || !memcmp( vec.data(), buffer, len ) ); if ( len > 10 ) { - try { - len = fc::from_base58( enc1, buffer, 10 ); - BOOST_CHECK( len <= 10 ); - } catch ( fc::exception expected ) {} + BOOST_CHECK_THROW(fc::from_base58( enc1, buffer, 10 ), fc::exception); } } diff --git a/tests/crypto/blowfish_test.cpp b/tests/crypto/blowfish_test.cpp index ec4ada7..ca55bca 100644 --- a/tests/crypto/blowfish_test.cpp +++ b/tests/crypto/blowfish_test.cpp @@ -75,9 +75,9 @@ const char key_test_ciphers[][17] = { const std::string chain_test_key = "0123456789ABCDEFF0E1D2C3B4A59687"; const std::string chain_test_iv = "FEDCBA9876543210"; -const std::string chain_test_plain = "7654321 Now is the time for \0\0\0\0"; const std::string chain_test_cbc = "6B77B4D63006DEE605B156E27403979358DEB9E7154616D959F1652BD5FF92CC"; const std::string chain_test_cfb = "E73214A2822139CAF26ECF6D2EB9E76E3DA3DE04D1517200519D57A6C3"; +const char* chain_test_plain = "7654321 Now is the time for \0\0\0\0"; BOOST_AUTO_TEST_SUITE(fc_crypto) @@ -85,9 +85,9 @@ BOOST_AUTO_TEST_CASE(blowfish_ecb_test) { for ( int i = 0; i < 34; i++ ) { unsigned char key[8], plain[8], cipher[8], out[8]; - BOOST_CHECK_EQUAL( 8, fc::from_hex( ecb_tests[i].key, (char*) key, sizeof(key) ) ); - BOOST_CHECK_EQUAL( 8, fc::from_hex( ecb_tests[i].plain, (char*) plain, sizeof(plain) ) ); - BOOST_CHECK_EQUAL( 8, fc::from_hex( ecb_tests[i].cipher, (char*) cipher, sizeof(cipher) ) ); + BOOST_CHECK_EQUAL( 8u, fc::from_hex( ecb_tests[i].key, (char*) key, sizeof(key) ) ); + BOOST_CHECK_EQUAL( 8u, fc::from_hex( ecb_tests[i].plain, (char*) plain, sizeof(plain) ) ); + BOOST_CHECK_EQUAL( 8u, fc::from_hex( ecb_tests[i].cipher, (char*) cipher, sizeof(cipher) ) ); fc::blowfish fish; fish.start( key, 8 ); @@ -105,11 +105,11 @@ BOOST_AUTO_TEST_CASE(blowfish_ecb_test) BOOST_AUTO_TEST_CASE(blowfish_key_test) { unsigned char key[24], plain[8], cipher[8], out[8]; - BOOST_CHECK_EQUAL( 24, fc::from_hex( key_test_key.c_str(), (char*) key, sizeof(key) ) ); - BOOST_CHECK_EQUAL( 8, fc::from_hex( key_test_plain.c_str(), (char*) plain, sizeof(plain) ) ); + BOOST_CHECK_EQUAL( 24u, fc::from_hex( key_test_key.c_str(), (char*) key, sizeof(key) ) ); + BOOST_CHECK_EQUAL( 8u, fc::from_hex( key_test_plain.c_str(), (char*) plain, sizeof(plain) ) ); for ( unsigned int i = 0; i < sizeof(key); i++ ) { - BOOST_CHECK_EQUAL( 8, fc::from_hex( key_test_ciphers[i], (char*) cipher, sizeof(cipher) ) ); + BOOST_CHECK_EQUAL( 8u, fc::from_hex( key_test_ciphers[i], (char*) cipher, sizeof(cipher) ) ); fc::blowfish fish; fish.start( key, i + 1 ); fish.encrypt( plain, out, 8, fc::blowfish::ECB ); @@ -133,37 +133,37 @@ static unsigned int from_bytes( const unsigned char* p ) { BOOST_AUTO_TEST_CASE(blowfish_chain_test) { unsigned char key[16], iv[8], cipher[32], out[32]; - BOOST_CHECK_EQUAL( 16, fc::from_hex( chain_test_key.c_str(), (char*) key, sizeof(key) ) ); - BOOST_CHECK_EQUAL( 8, fc::from_hex( chain_test_iv.c_str(), (char*) iv, sizeof(iv) ) ); + BOOST_CHECK_EQUAL( 16u, fc::from_hex( chain_test_key.c_str(), (char*) key, sizeof(key) ) ); + BOOST_CHECK_EQUAL( 8u, fc::from_hex( chain_test_iv.c_str(), (char*) iv, sizeof(iv) ) ); - BOOST_CHECK_EQUAL( 32, fc::from_hex( chain_test_cbc.c_str(), (char*) cipher, sizeof(cipher) ) ); + BOOST_CHECK_EQUAL( 32u, fc::from_hex( chain_test_cbc.c_str(), (char*) cipher, sizeof(cipher) ) ); fc::blowfish fish; fish.start( key, sizeof(key), fc::sblock( from_bytes( iv ), from_bytes( iv + 4 ) ) ); - fish.encrypt( (unsigned char*) chain_test_plain.c_str(), out, sizeof(out), fc::blowfish::CBC ); + fish.encrypt( (unsigned char*) chain_test_plain, out, sizeof(out), fc::blowfish::CBC ); BOOST_CHECK( !memcmp( cipher, out, sizeof(cipher) ) ); fish.reset_chain(); fish.decrypt( out, sizeof(out), fc::blowfish::CBC ); - BOOST_CHECK( !memcmp( chain_test_plain.c_str(), out, 29 ) ); + BOOST_CHECK( !memcmp( chain_test_plain, out, 29 ) ); fish.reset_chain(); fish.encrypt( out, sizeof(out), fc::blowfish::CBC ); BOOST_CHECK( !memcmp( cipher, out, sizeof(cipher) ) ); fish.reset_chain(); fish.decrypt( cipher, out, sizeof(cipher), fc::blowfish::CBC ); - BOOST_CHECK( !memcmp( chain_test_plain.c_str(), out, 29 ) ); + BOOST_CHECK( !memcmp( chain_test_plain, out, 29 ) ); - BOOST_CHECK_EQUAL( 29, fc::from_hex( chain_test_cfb.c_str(), (char*) cipher, sizeof(cipher) ) ); + BOOST_CHECK_EQUAL( 29u, fc::from_hex( chain_test_cfb.c_str(), (char*) cipher, sizeof(cipher) ) ); fish.reset_chain(); - fish.encrypt( (unsigned char*) chain_test_plain.c_str(), out, sizeof(out), fc::blowfish::CFB ); + fish.encrypt( (unsigned char*) chain_test_plain, out, sizeof(out), fc::blowfish::CFB ); BOOST_CHECK( !memcmp( cipher, out, 29 ) ); fish.reset_chain(); memset( out + 29, 0, 3 ); fish.decrypt( out, sizeof(out), fc::blowfish::CFB ); - BOOST_CHECK( !memcmp( chain_test_plain.c_str(), out, 29 ) ); + BOOST_CHECK( !memcmp( chain_test_plain, out, 29 ) ); fish.reset_chain(); memset( out + 29, 0, 3 ); fish.encrypt( out, sizeof(out), fc::blowfish::CFB ); BOOST_CHECK( !memcmp( cipher, out, 29 ) ); fish.reset_chain(); memset( out + 29, 0, 3 ); fish.decrypt( cipher, out, sizeof(cipher), fc::blowfish::CFB ); - BOOST_CHECK( !memcmp( chain_test_plain.c_str(), out, 29 ) ); + BOOST_CHECK( !memcmp( chain_test_plain, out, 29 ) ); } BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/crypto/rand_test.cpp b/tests/crypto/rand_test.cpp index 09533be..6d6a26f 100644 --- a/tests/crypto/rand_test.cpp +++ b/tests/crypto/rand_test.cpp @@ -21,7 +21,9 @@ static void check_randomness( const char* buffer, size_t len ) { double E = 1 + (zc + oc) / 2.0; double variance = (E - 1) * (E - 2) / (oc + zc - 1); double sigma = sqrt(variance); - BOOST_CHECK( rc > E - sigma && rc < E + sigma); + + BOOST_CHECK_GT(rc, E - sigma); + BOOST_CHECK_LT(rc, E + sigma); } BOOST_AUTO_TEST_SUITE(fc_crypto) diff --git a/tests/crypto/sha_tests.cpp b/tests/crypto/sha_tests.cpp index 850c2f8..104f0c2 100644 --- a/tests/crypto/sha_tests.cpp +++ b/tests/crypto/sha_tests.cpp @@ -75,7 +75,7 @@ void test_big( const std::string& expected ) { template void test_stream( ) { - H hash( TEST1 ); + H hash = H::hash( TEST1 ); std::stringstream stream; stream << hash; diff --git a/tests/hmac_test.cpp b/tests/hmac_test.cpp index a8f21dd..140b211 100644 --- a/tests/hmac_test.cpp +++ b/tests/hmac_test.cpp @@ -72,7 +72,7 @@ static fc::hmac mac_224; static fc::hmac mac_256; static fc::hmac mac_512; -template +template static void run_test( const fc::string& key, const fc::string& data, const fc::string& expect_224, const fc::string& expect_256, const fc::string& expect_512 ) { diff --git a/tests/network/http/websocket_test.cpp b/tests/network/http/websocket_test.cpp index 03bfdd1..83fcba9 100644 --- a/tests/network/http/websocket_test.cpp +++ b/tests/network/http/websocket_test.cpp @@ -39,7 +39,7 @@ BOOST_AUTO_TEST_CASE(websocket_test) try { c_conn->send_message( "again" ); BOOST_FAIL("expected assertion failure"); - } catch (const fc::assert_exception& e) { + } catch (const fc::exception& e) { //std::cerr << e.to_string() << "\n"; } @@ -55,14 +55,14 @@ BOOST_AUTO_TEST_CASE(websocket_test) try { c_conn->send_message( "again" ); BOOST_FAIL("expected assertion failure"); - } catch (const fc::assert_exception& e) { + } catch (const fc::exception& e) { std::cerr << e.to_string() << "\n"; } try { c_conn = client.connect( "ws://localhost:8090" ); BOOST_FAIL("expected assertion failure"); - } catch (const fc::assert_exception& e) { + } catch (const fc::exception& e) { std::cerr << e.to_string() << "\n"; } } diff --git a/tests/real128_test.cpp b/tests/real128_test.cpp index beae9b7..5020af9 100644 --- a/tests/real128_test.cpp +++ b/tests/real128_test.cpp @@ -11,9 +11,9 @@ BOOST_AUTO_TEST_CASE(real128_test) { BOOST_CHECK_EQUAL(string(real128()), string("0.")); BOOST_CHECK_EQUAL(string(real128(0)), string("0.")); - BOOST_CHECK_EQUAL(real128(8).to_uint64(), 8); - BOOST_CHECK_EQUAL(real128(6789).to_uint64(), 6789); - BOOST_CHECK_EQUAL(real128(10000).to_uint64(), 10000); + BOOST_CHECK_EQUAL(real128(8).to_uint64(), 8u); + BOOST_CHECK_EQUAL(real128(6789).to_uint64(), 6789u); + BOOST_CHECK_EQUAL(real128(10000).to_uint64(), 10000u); BOOST_CHECK_EQUAL(string(real128(1)), string("1.")); BOOST_CHECK_EQUAL(string(real128(5)), string("5.")); BOOST_CHECK_EQUAL(string(real128(12345)), string("12345.")); @@ -41,8 +41,8 @@ BOOST_AUTO_TEST_CASE(real128_test) BOOST_CHECK_EQUAL( string(pi*1), "3.1415926535" ); BOOST_CHECK_EQUAL( string(pi*0), "0." ); - BOOST_CHECK_EQUAL(real128("12345.6789").to_uint64(), 12345); - BOOST_CHECK_EQUAL((real128("12345.6789")*10000).to_uint64(), 123456789); + BOOST_CHECK_EQUAL(real128("12345.6789").to_uint64(), 12345u); + BOOST_CHECK_EQUAL((real128("12345.6789")*10000).to_uint64(), 123456789u); BOOST_CHECK_EQUAL(string(real128("12345.6789")), string("12345.6789")); BOOST_CHECK_EQUAL( real128(uint64_t(-1)).to_uint64(), uint64_t(-1) );