sanitize, remove warnings

This commit is contained in:
Alexey Frolov 2018-02-02 15:29:46 +03:00
parent 226391bbbc
commit 5138c58e09
23 changed files with 91 additions and 73 deletions

View file

@ -231,6 +231,8 @@ namespace fc { namespace json_relaxed
} }
} FC_RETHROW_EXCEPTIONS( warn, "while parsing string" ); } FC_RETHROW_EXCEPTIONS( warn, "while parsing string" );
return {};
} }
struct CharValueTable struct CharValueTable

View file

@ -181,7 +181,7 @@ class static_variant {
static_assert(impl::type_info<Types...>::no_reference_types, "Reference types are not permitted in static_variant."); static_assert(impl::type_info<Types...>::no_reference_types, "Reference types are not permitted in static_variant.");
static_assert(impl::type_info<Types...>::no_duplicates, "static_variant type arguments contain duplicate types."); static_assert(impl::type_info<Types...>::no_duplicates, "static_variant type arguments contain duplicate types.");
int _tag; size_t _tag;
char storage[impl::type_info<Types...>::size]; char storage[impl::type_info<Types...>::size];
template<typename X> template<typename X>
@ -326,15 +326,14 @@ public:
} }
static int count() { return impl::type_info<Types...>::count; } static int count() { return impl::type_info<Types...>::count; }
void set_which( int w ) { void set_which( size_t w ) {
FC_ASSERT( w >= 0 );
FC_ASSERT( w < count() ); FC_ASSERT( w < count() );
this->~static_variant(); this->~static_variant();
_tag = w; _tag = w;
impl::storage_ops<0, Types...>::con(_tag, storage); impl::storage_ops<0, Types...>::con(_tag, storage);
} }
int which() const {return _tag;} size_t which() const {return _tag;}
}; };
template<typename Result> template<typename Result>

View file

@ -32,6 +32,7 @@ namespace fc {
an existing "unknown" boost thread). In such cases, thread_d doesn't have access boost::thread object. an existing "unknown" boost thread). In such cases, thread_d doesn't have access boost::thread object.
*/ */
static thread& current(); static thread& current();
static void cleanup();
/** /**

View file

@ -3,6 +3,7 @@
#include <boost/thread.hpp> #include <boost/thread.hpp>
#include <fc/log/logger.hpp> #include <fc/log/logger.hpp>
#include <fc/exception/exception.hpp> #include <fc/exception/exception.hpp>
#include <boost/scope_exit.hpp>
namespace fc { namespace fc {
namespace asio { namespace asio {
@ -104,6 +105,13 @@ namespace fc {
asio_threads.push_back( new boost::thread( [=]() asio_threads.push_back( new boost::thread( [=]()
{ {
fc::thread::current().set_name("asio"); fc::thread::current().set_name("asio");
BOOST_SCOPE_EXIT(void)
{
fc::thread::cleanup();
}
BOOST_SCOPE_EXIT_END
while (!io->stopped()) while (!io->stopped())
{ {
try try

View file

@ -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; 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); 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 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; if (TDEFL_READ_UNALIGNED_WORD(&d->m_dict[probe_pos + match_len - 1]) == c01) break;
TDEFL_PROBE; TDEFL_PROBE; TDEFL_PROBE; 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)) && 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) ); (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) if (!probe_len)
@ -2848,7 +2848,7 @@ void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h,
#include <stdio.h> #include <stdio.h>
#include <sys/stat.h> #include <sys/stat.h>
#if defined(_MSC_VER) #if defined(_MSC_VER)
static FILE *mz_fopen(const char *pFilename, const char *pMode) static FILE *mz_fopen(const char *pFilename, const char *pMode)
{ {
FILE* pFile = NULL; FILE* pFile = NULL;

View file

@ -29,7 +29,7 @@ struct aes_encoder::impl
aes_encoder::aes_encoder() aes_encoder::aes_encoder()
{ {
static int init = init_openssl(); static __attribute__((unused)) int init = init_openssl();
} }
aes_encoder::~aes_encoder() 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", FC_THROW_EXCEPTION( aes_exception, "error during aes 256 cbc encryption update",
("s", ERR_error_string( ERR_get_error(), nullptr) ) ); ("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; return ciphertext_len;
} }
#if 0 #if 0
@ -96,9 +96,9 @@ struct aes_decoder::impl
}; };
aes_decoder::aes_decoder() 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 ) 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", FC_THROW_EXCEPTION( aes_exception, "error during aes 256 cbc decryption update",
("s", ERR_error_string( ERR_get_error(), nullptr) ) ); ("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; return plaintext_len;
} }
#if 0 #if 0

View file

@ -76,7 +76,10 @@ namespace fc
while (len > 0 && *first == 0) { first++; len--; } while (len > 0 && *first == 0) { first++; len--; }
std::vector<char> result; std::vector<char> result;
result.resize(leading_zeros + len, 0); result.resize(leading_zeros + len, 0);
memcpy( result.data() + leading_zeros, first, len ); if (len)
{
memcpy( result.data() + leading_zeros, first, len );
}
return result; return result;
} }
} }

View file

@ -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_THROW_EXCEPTION( parse_error_exception, "Unable to decode base58 string ${base58_str}", ("base58_str",base58_str) );
} }
FC_ASSERT( out.size() <= out_data_len ); 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(); return out.size();
} }
} }

View file

@ -85,8 +85,8 @@ namespace fc { namespace ecc {
ssl_bignum order; ssl_bignum order;
FC_ASSERT( EC_GROUP_get_order( group, order, ctx ) ); FC_ASSERT( EC_GROUP_get_order( group, order, ctx ) );
private_key_secret bin; private_key_secret bin;
FC_ASSERT( BN_num_bytes( order ) == bin.data_size() ); FC_ASSERT( (size_t) BN_num_bytes( order ) == bin.data_size() );
FC_ASSERT( BN_bn2bin( order, (unsigned char*) bin.data() ) == bin.data_size() ); FC_ASSERT( (size_t) BN_bn2bin( order, (unsigned char*) bin.data() ) == bin.data_size() );
return bin; return bin;
} }
@ -104,8 +104,8 @@ namespace fc { namespace ecc {
FC_ASSERT( EC_GROUP_get_order( group, order, ctx ) ); FC_ASSERT( EC_GROUP_get_order( group, order, ctx ) );
BN_rshift1( order, order ); BN_rshift1( order, order );
private_key_secret bin; private_key_secret bin;
FC_ASSERT( BN_num_bytes( order ) == bin.data_size() ); FC_ASSERT( (size_t) BN_num_bytes( order ) == bin.data_size() );
FC_ASSERT( BN_bn2bin( order, (unsigned char*) bin.data() ) == bin.data_size() ); FC_ASSERT( (size_t) BN_bn2bin( order, (unsigned char*) bin.data() ) == bin.data_size() );
return bin; return bin;
} }

View file

@ -29,9 +29,8 @@ namespace fc { namespace ecc {
} }
void _init_lib() { void _init_lib() {
static const secp256k1_context_t* ctx = _get_context(); static __attribute__((unused)) const secp256k1_context_t* ctx = _get_context();
static int init_o = init_openssl(); static __attribute__((unused)) int init_o = init_openssl();
(void)ctx;
} }
class public_key_impl class public_key_impl

View file

@ -8,7 +8,7 @@ namespace fc {
void rand_bytes(char* buf, int count) 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); int result = RAND_bytes((unsigned char*)buf, count);
if (result != 1) if (result != 1)
@ -17,7 +17,7 @@ void rand_bytes(char* buf, int count)
void rand_pseudo_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); int result = RAND_pseudo_bytes((unsigned char*)buf, count);
if (result == -1) if (result == -1)

View file

@ -136,7 +136,7 @@ char * dupstr (const char* s) {
char* my_generator(const char* text, int state) char* my_generator(const char* text, int state)
{ {
static int list_index, len; static size_t list_index, len;
const char *name; const char *name;
if (!state) { 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) static char** cli_completion( const char * text , int start, int end)
{ {
char **matches; char **matches;
matches = (char **)NULL; matches = (char **)NULL;
#ifdef HAVE_READLINE
if (start == 0) if (start == 0)
matches = rl_completion_matches ((char*)text, &my_generator); matches = rl_completion_matches ((char*)text, &my_generator);
else else
rl_bind_key('\t',rl_abort); rl_bind_key('\t',rl_abort);
#endif
return (matches); return (matches);
} }
#endif
void cli::getline( const fc::string& prompt, fc::string& line) void cli::getline( const fc::string& prompt, fc::string& line)

View file

@ -15,7 +15,7 @@ namespace fc {
mutex::~mutex() { mutex::~mutex() {
if( m_blist ) if( m_blist )
{ {
context* c = m_blist; // context* c = m_blist;
fc::thread::current().debug("~mutex"); fc::thread::current().debug("~mutex");
#if 0 #if 0
while( c ) { while( c ) {

View file

@ -113,8 +113,10 @@ namespace fc {
if( my ) if( my )
{ {
// wlog( "calling quit() on ${n}",("n",my->name) ); // wlog( "calling quit() on ${n}",("n",my->name) );
quit(); // deletes `my` quit();
} }
delete my;
} }
thread& thread::current() { thread& thread::current() {
@ -123,6 +125,11 @@ namespace fc {
return *current_thread(); return *current_thread();
} }
void thread::cleanup() {
delete current_thread();
current_thread() = nullptr;
}
const string& thread::name()const const string& thread::name()const
{ {
return my->name; return my->name;
@ -152,19 +159,18 @@ namespace fc {
{ {
//if quitting from a different thread, start quit task on thread. //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 we have and know our attached boost thread, wait for it to finish, then return.
if( &current() != this ) if( !is_current() )
{ {
auto t = my->boost_thread;
async( [=](){quit();}, "thread::quit" );//.wait(); async( [=](){quit();}, "thread::quit" );//.wait();
if( my->boost_thread ) if( t )
{ {
//wlog("destroying boost thread ${tid}",("tid",(uintptr_t)my->boost_thread->native_handle())); //wlog("destroying boost thread ${tid}",("tid",(uintptr_t)my->boost_thread->native_handle()));
my->boost_thread->join(); t->join();
delete my;
my = nullptr;
} }
return; return;
} }
my->done = true; my->done = true;
// wlog( "${s}", ("s",name()) ); // wlog( "${s}", ("s",name()) );
// We are quiting from our own thread... // We are quiting from our own thread...

View file

@ -13,7 +13,6 @@ namespace fc {
bool is_utf8( const std::string& str ) bool is_utf8( const std::string& str )
{ {
auto itr = utf8::find_invalid(str.begin(), str.end());
return utf8::is_valid( str.begin(), str.end() ); return utf8::is_valid( str.begin(), str.end() );
} }

View file

@ -48,7 +48,7 @@ BOOST_AUTO_TEST_CASE(bloom_test_1)
std::string line; std::string line;
std::ifstream in("README.md"); std::ifstream in("README.md");
std::ofstream words("words.txt"); std::ofstream words("words.txt");
while( !in.eof() && count < 100000 ) while( in.good() && count < 100000 )
{ {
std::getline(in, line); std::getline(in, line);
// std::cout << "'"<<line<<"'\n"; // std::cout << "'"<<line<<"'\n";

View file

@ -23,7 +23,7 @@ static void test_16( const std::string& test, const std::string& expected )
BOOST_CHECK_EQUAL( expected, enc2 ); BOOST_CHECK_EQUAL( expected, enc2 );
char out[32]; char out[32];
int len = fc::from_hex( enc1, out, 32 ); size_t len = fc::from_hex( enc1, out, 32 );
BOOST_CHECK_EQUAL( test.size(), len ); BOOST_CHECK_EQUAL( test.size(), len );
BOOST_CHECK( !memcmp( test.c_str(), out, len ) ); BOOST_CHECK( !memcmp( test.c_str(), out, len ) );
if (len > 10) { if (len > 10) {
@ -53,7 +53,7 @@ static void test_36( const std::string& test, const std::string& expected )
std::vector<char> dec = fc::from_base36( enc1 ); std::vector<char> dec = fc::from_base36( enc1 );
BOOST_CHECK_EQUAL( vec.size(), dec.size() ); 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) BOOST_AUTO_TEST_CASE(base36_test)
@ -76,17 +76,14 @@ static void test_58( const std::string& test, const std::string& expected )
std::vector<char> dec = fc::from_base58( enc1 ); std::vector<char> dec = fc::from_base58( enc1 );
BOOST_CHECK_EQUAL( vec.size(), dec.size() ); BOOST_CHECK_EQUAL( vec.size(), dec.size() );
BOOST_CHECK( !memcmp( vec.data(), dec.data(), vec.size() ) ); BOOST_CHECK( vec == dec );
char buffer[64]; char buffer[64];
size_t len = fc::from_base58( enc1, buffer, 64 ); size_t len = fc::from_base58( enc1, buffer, 64 );
BOOST_CHECK( len <= 64 ); BOOST_CHECK( len <= 64 );
BOOST_CHECK( !memcmp( vec.data(), buffer, len ) ); BOOST_CHECK( vec.empty() || !memcmp( vec.data(), buffer, len ) );
if ( len > 10 ) { if ( len > 10 ) {
try { BOOST_CHECK_THROW(fc::from_base58( enc1, buffer, 10 ), fc::exception);
len = fc::from_base58( enc1, buffer, 10 );
BOOST_CHECK( len <= 10 );
} catch ( fc::exception expected ) {}
} }
} }

View file

@ -75,9 +75,9 @@ const char key_test_ciphers[][17] = {
const std::string chain_test_key = "0123456789ABCDEFF0E1D2C3B4A59687"; const std::string chain_test_key = "0123456789ABCDEFF0E1D2C3B4A59687";
const std::string chain_test_iv = "FEDCBA9876543210"; 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_cbc = "6B77B4D63006DEE605B156E27403979358DEB9E7154616D959F1652BD5FF92CC";
const std::string chain_test_cfb = "E73214A2822139CAF26ECF6D2EB9E76E3DA3DE04D1517200519D57A6C3"; 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) BOOST_AUTO_TEST_SUITE(fc_crypto)
@ -85,9 +85,9 @@ BOOST_AUTO_TEST_CASE(blowfish_ecb_test)
{ {
for ( int i = 0; i < 34; i++ ) { for ( int i = 0; i < 34; i++ ) {
unsigned char key[8], plain[8], cipher[8], out[8]; 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( 8u, 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( 8u, 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].cipher, (char*) cipher, sizeof(cipher) ) );
fc::blowfish fish; fc::blowfish fish;
fish.start( key, 8 ); fish.start( key, 8 );
@ -105,11 +105,11 @@ BOOST_AUTO_TEST_CASE(blowfish_ecb_test)
BOOST_AUTO_TEST_CASE(blowfish_key_test) BOOST_AUTO_TEST_CASE(blowfish_key_test)
{ {
unsigned char key[24], plain[8], cipher[8], out[8]; 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( 24u, 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( 8u, fc::from_hex( key_test_plain.c_str(), (char*) plain, sizeof(plain) ) );
for ( unsigned int i = 0; i < sizeof(key); i++ ) { 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; fc::blowfish fish;
fish.start( key, i + 1 ); fish.start( key, i + 1 );
fish.encrypt( plain, out, 8, fc::blowfish::ECB ); 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) BOOST_AUTO_TEST_CASE(blowfish_chain_test)
{ {
unsigned char key[16], iv[8], cipher[32], out[32]; 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( 16u, 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( 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; fc::blowfish fish;
fish.start( key, sizeof(key), fc::sblock( from_bytes( iv ), from_bytes( iv + 4 ) ) ); 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) ) ); BOOST_CHECK( !memcmp( cipher, out, sizeof(cipher) ) );
fish.reset_chain(); fish.reset_chain();
fish.decrypt( out, sizeof(out), fc::blowfish::CBC ); 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.reset_chain();
fish.encrypt( out, sizeof(out), fc::blowfish::CBC ); fish.encrypt( out, sizeof(out), fc::blowfish::CBC );
BOOST_CHECK( !memcmp( cipher, out, sizeof(cipher) ) ); BOOST_CHECK( !memcmp( cipher, out, sizeof(cipher) ) );
fish.reset_chain(); fish.reset_chain();
fish.decrypt( cipher, out, sizeof(cipher), fc::blowfish::CBC ); 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.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 ) ); BOOST_CHECK( !memcmp( cipher, out, 29 ) );
fish.reset_chain(); memset( out + 29, 0, 3 ); fish.reset_chain(); memset( out + 29, 0, 3 );
fish.decrypt( out, sizeof(out), fc::blowfish::CFB ); 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.reset_chain(); memset( out + 29, 0, 3 );
fish.encrypt( out, sizeof(out), fc::blowfish::CFB ); fish.encrypt( out, sizeof(out), fc::blowfish::CFB );
BOOST_CHECK( !memcmp( cipher, out, 29 ) ); BOOST_CHECK( !memcmp( cipher, out, 29 ) );
fish.reset_chain(); memset( out + 29, 0, 3 ); fish.reset_chain(); memset( out + 29, 0, 3 );
fish.decrypt( cipher, out, sizeof(cipher), fc::blowfish::CFB ); 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() BOOST_AUTO_TEST_SUITE_END()

View file

@ -21,7 +21,9 @@ static void check_randomness( const char* buffer, size_t len ) {
double E = 1 + (zc + oc) / 2.0; double E = 1 + (zc + oc) / 2.0;
double variance = (E - 1) * (E - 2) / (oc + zc - 1); double variance = (E - 1) * (E - 2) / (oc + zc - 1);
double sigma = sqrt(variance); 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) BOOST_AUTO_TEST_SUITE(fc_crypto)

View file

@ -75,7 +75,7 @@ void test_big( const std::string& expected ) {
template<typename H> template<typename H>
void test_stream( ) { void test_stream( ) {
H hash( TEST1 ); H hash = H::hash( TEST1 );
std::stringstream stream; std::stringstream stream;
stream << hash; stream << hash;

View file

@ -72,7 +72,7 @@ static fc::hmac<fc::sha224> mac_224;
static fc::hmac<fc::sha256> mac_256; static fc::hmac<fc::sha256> mac_256;
static fc::hmac<fc::sha512> mac_512; static fc::hmac<fc::sha512> mac_512;
template<int N,int M> template<size_t N,size_t M>
static void run_test( const fc::string& key, const fc::string& data, const fc::string& expect_224, 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 ) const fc::string& expect_256, const fc::string& expect_512 )
{ {

View file

@ -39,7 +39,7 @@ BOOST_AUTO_TEST_CASE(websocket_test)
try { try {
c_conn->send_message( "again" ); c_conn->send_message( "again" );
BOOST_FAIL("expected assertion failure"); BOOST_FAIL("expected assertion failure");
} catch (const fc::assert_exception& e) { } catch (const fc::exception& e) {
//std::cerr << e.to_string() << "\n"; //std::cerr << e.to_string() << "\n";
} }
@ -55,14 +55,14 @@ BOOST_AUTO_TEST_CASE(websocket_test)
try { try {
c_conn->send_message( "again" ); c_conn->send_message( "again" );
BOOST_FAIL("expected assertion failure"); BOOST_FAIL("expected assertion failure");
} catch (const fc::assert_exception& e) { } catch (const fc::exception& e) {
std::cerr << e.to_string() << "\n"; std::cerr << e.to_string() << "\n";
} }
try { try {
c_conn = client.connect( "ws://localhost:8090" ); c_conn = client.connect( "ws://localhost:8090" );
BOOST_FAIL("expected assertion failure"); BOOST_FAIL("expected assertion failure");
} catch (const fc::assert_exception& e) { } catch (const fc::exception& e) {
std::cerr << e.to_string() << "\n"; std::cerr << e.to_string() << "\n";
} }
} }

View file

@ -11,9 +11,9 @@ BOOST_AUTO_TEST_CASE(real128_test)
{ {
BOOST_CHECK_EQUAL(string(real128()), string("0.")); BOOST_CHECK_EQUAL(string(real128()), string("0."));
BOOST_CHECK_EQUAL(string(real128(0)), string("0.")); BOOST_CHECK_EQUAL(string(real128(0)), string("0."));
BOOST_CHECK_EQUAL(real128(8).to_uint64(), 8); BOOST_CHECK_EQUAL(real128(8).to_uint64(), 8u);
BOOST_CHECK_EQUAL(real128(6789).to_uint64(), 6789); BOOST_CHECK_EQUAL(real128(6789).to_uint64(), 6789u);
BOOST_CHECK_EQUAL(real128(10000).to_uint64(), 10000); BOOST_CHECK_EQUAL(real128(10000).to_uint64(), 10000u);
BOOST_CHECK_EQUAL(string(real128(1)), string("1.")); BOOST_CHECK_EQUAL(string(real128(1)), string("1."));
BOOST_CHECK_EQUAL(string(real128(5)), string("5.")); BOOST_CHECK_EQUAL(string(real128(5)), string("5."));
BOOST_CHECK_EQUAL(string(real128(12345)), string("12345.")); 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*1), "3.1415926535" );
BOOST_CHECK_EQUAL( string(pi*0), "0." ); BOOST_CHECK_EQUAL( string(pi*0), "0." );
BOOST_CHECK_EQUAL(real128("12345.6789").to_uint64(), 12345); BOOST_CHECK_EQUAL(real128("12345.6789").to_uint64(), 12345u);
BOOST_CHECK_EQUAL((real128("12345.6789")*10000).to_uint64(), 123456789); BOOST_CHECK_EQUAL((real128("12345.6789")*10000).to_uint64(), 123456789u);
BOOST_CHECK_EQUAL(string(real128("12345.6789")), string("12345.6789")); BOOST_CHECK_EQUAL(string(real128("12345.6789")), string("12345.6789"));
BOOST_CHECK_EQUAL( real128(uint64_t(-1)).to_uint64(), uint64_t(-1) ); BOOST_CHECK_EQUAL( real128(uint64_t(-1)).to_uint64(), uint64_t(-1) );