From dbbd97179333e956276448025d465b176c71fb58 Mon Sep 17 00:00:00 2001 From: Khaled Al-Hassanieh Date: Thu, 8 Mar 2018 15:46:21 -0500 Subject: [PATCH] Changes in order to get rid of contract warnings --- contracts/asserter/asserter.cpp | 2 +- contracts/eosiolib/fixedpoint.hpp | 12 +- contracts/eosiolib/print.hpp | 4 +- contracts/eosiolib/real.hpp | 2 +- contracts/eosiolib/singleton.hpp | 2 +- contracts/identity/identity.hpp | 2 +- contracts/identity/test/identity_test.cpp | 4 +- contracts/noop/noop.hpp | 2 - contracts/simpledb/simpledb.cpp | 32 ++-- contracts/test_api/test_action.cpp | 4 +- contracts/test_api/test_api.cpp | 2 +- contracts/test_api/test_api.hpp | 2 +- contracts/test_api/test_compiler_builtins.cpp | 163 +++++++++--------- contracts/test_api/test_crypto.cpp | 13 +- contracts/test_api/test_fixedpoint.cpp | 150 ++++++++-------- contracts/test_api/test_math.cpp | 18 +- contracts/test_api/test_print.cpp | 43 ++--- contracts/test_api/test_real.cpp | 4 + contracts/test_api/test_transaction.cpp | 31 ++-- contracts/test_api/test_types.cpp | 4 +- contracts/test_api_db/test_db.cpp | 45 +++-- contracts/test_api_mem/test_api_mem.cpp | 2 +- .../test_api_mem/test_extended_memory.cpp | 6 +- contracts/test_api_mem/test_memory.cpp | 3 +- 24 files changed, 275 insertions(+), 277 deletions(-) diff --git a/contracts/asserter/asserter.cpp b/contracts/asserter/asserter.cpp index 059d50d86..9a0706c3e 100644 --- a/contracts/asserter/asserter.cpp +++ b/contracts/asserter/asserter.cpp @@ -29,7 +29,7 @@ extern "C" { } // maybe assert? - eosio_assert(def->condition, def->message); + eosio_assert((uint32_t)def->condition, def->message); } else if( action == N(provereset) ) { eosio_assert(global_variable == 45, "Global Variable Initialized poorly"); global_variable = 100; diff --git a/contracts/eosiolib/fixedpoint.hpp b/contracts/eosiolib/fixedpoint.hpp index e2836ef19..5c074fd17 100644 --- a/contracts/eosiolib/fixedpoint.hpp +++ b/contracts/eosiolib/fixedpoint.hpp @@ -147,11 +147,11 @@ ope * fixed_point128<3> b(a); */ uint128_t frac_part() const { if(!Q) return 0; - return val << (32-Q); + return uint128_t(val << (32-Q)); } void print() const { - uint128_t ip(int_part()); + uint128_t ip((uint128_t)int_part()); uint128_t fp(frac_part()); printi128(&ip); prints("."); @@ -230,7 +230,7 @@ ope * fixed_point128<3> b(a); */ uint64_t frac_part() const { if(!Q) return 0; - return val << (32-Q); + return uint64_t(val << (32-Q)); } void print() const { @@ -306,7 +306,7 @@ ope * fixed_point128<3> b(a); } uint32_t frac_part() const { if(!Q) return 0; - return val << (32-Q); + return uint32_t(val << (32-Q)); } void print() const { @@ -576,7 +576,7 @@ ope * fixed_point128<3> b(a); { eosio_assert( rhs != 0, "divide by zero" ); - fixed_point64 result = fixed_point32<0>(lhs) / fixed_point32<0>(rhs); + fixed_point64 result = fixed_point32<0>((int32_t)lhs) / fixed_point32<0>((int32_t)rhs); return result; } @@ -595,7 +595,7 @@ ope * fixed_point128<3> b(a); { eosio_assert( rhs != 0, "divide by zero" ); - fixed_point128 result = fixed_point64<0>(lhs) / fixed_point64<0>(rhs); + fixed_point128 result = fixed_point64<0>((int32_t)lhs) / fixed_point64<0>((int32_t)rhs); return fixed_point128(result); } diff --git a/contracts/eosiolib/print.hpp b/contracts/eosiolib/print.hpp index 2104ea833..30f4e0184 100644 --- a/contracts/eosiolib/print.hpp +++ b/contracts/eosiolib/print.hpp @@ -1,4 +1,4 @@ -/** +/** * @file * @copyright defined in eos/LICENSE.txt */ @@ -50,7 +50,7 @@ namespace eosio { } inline void print( long num ) { - printi(num); + printi(uint64_t(num)); } /** diff --git a/contracts/eosiolib/real.hpp b/contracts/eosiolib/real.hpp index 6a6a394d9..c05b08790 100644 --- a/contracts/eosiolib/real.hpp +++ b/contracts/eosiolib/real.hpp @@ -30,7 +30,7 @@ namespace eosio { * @brief Constructor to double object from uint64 value * * @details Constructor to double object from uint64 value - * @param val data + * @param _val data */ real(const uint64_t &_val) : val(_val) {} diff --git a/contracts/eosiolib/singleton.hpp b/contracts/eosiolib/singleton.hpp index 83ee38e0d..1f9701003 100644 --- a/contracts/eosiolib/singleton.hpp +++ b/contracts/eosiolib/singleton.hpp @@ -20,7 +20,7 @@ namespace eosio { uint64_t primary_key() const { return pk_value; } - EOSLIB_SERIALIZE( row, (value) ); + EOSLIB_SERIALIZE( row, (value) ) }; typedef eosio::multi_index table; diff --git a/contracts/identity/identity.hpp b/contracts/identity/identity.hpp index 70919d759..b1dc66a5c 100644 --- a/contracts/identity/identity.hpp +++ b/contracts/identity/identity.hpp @@ -155,7 +155,7 @@ namespace identity { uint64_t primary_key() const { return account; } - EOSLIB_SERIALIZE( trustrow, (account) ); + EOSLIB_SERIALIZE( trustrow, (account) ) }; typedef eosio::multi_index { account_name account ; - EOSLIB_SERIALIZE( get_identity_for_account, (account) ); + EOSLIB_SERIALIZE( get_identity_for_account, (account) ) }; typedef singleton result_table; diff --git a/contracts/noop/noop.hpp b/contracts/noop/noop.hpp index 51d718596..24bdc61a9 100644 --- a/contracts/noop/noop.hpp +++ b/contracts/noop/noop.hpp @@ -7,8 +7,6 @@ #include #include -using namespace eosio; - namespace noop { using std::string; diff --git a/contracts/simpledb/simpledb.cpp b/contracts/simpledb/simpledb.cpp index 0441a10e0..aebe16c11 100644 --- a/contracts/simpledb/simpledb.cpp +++ b/contracts/simpledb/simpledb.cpp @@ -35,7 +35,7 @@ namespace simpledb { int16_t i16; int8_t i8; - EOSLIB_SERIALIZE( record1, (key)(u128)(u64)(u32)(u16)(u8)(i64)(i32)(i16)(i8) ); + EOSLIB_SERIALIZE( record1, (key)(u128)(u64)(u32)(u16)(u8)(i64)(i32)(i16)(i8) ) }; //@abi action insert1 @@ -46,7 +46,7 @@ namespace simpledb { store_i64( N(simpledb), N(record1), N(simpledb), b.data(), b.size()); } - EOSLIB_SERIALIZE( insert_record1, (r1) ); + EOSLIB_SERIALIZE( insert_record1, (r1) ) }; //@abi action remove1 @@ -56,7 +56,7 @@ namespace simpledb { remove_i64( N(simpledb), N(record1), (char *)this); } - EOSLIB_SERIALIZE( remove_record1, (key) ); + EOSLIB_SERIALIZE( remove_record1, (key) ) }; //@abi table @@ -64,7 +64,7 @@ namespace simpledb { uint128_t key1; uint128_t key2; - EOSLIB_SERIALIZE( record2, (key1)(key2) ); + EOSLIB_SERIALIZE( record2, (key1)(key2) ) }; //@abi action insert2 @@ -75,7 +75,7 @@ namespace simpledb { store_i128i128( N(simpledb), N(record2), N(simpledb), b.data(), b.size()); } - EOSLIB_SERIALIZE( insert_record2, (r2) ); + EOSLIB_SERIALIZE( insert_record2, (r2) ) }; //@abi action remove2 @@ -86,7 +86,7 @@ namespace simpledb { remove_i128i128( N(simpledb), N(record2), b.data()); } - EOSLIB_SERIALIZE( remove_record2, (key) ); + EOSLIB_SERIALIZE( remove_record2, (key) ) }; //@abi table @@ -95,7 +95,7 @@ namespace simpledb { uint64_t key2; uint64_t key3; - EOSLIB_SERIALIZE( record3, (key1)(key2)(key3) ); + EOSLIB_SERIALIZE( record3, (key1)(key2)(key3) ) }; //@abi action insert3 @@ -106,7 +106,7 @@ namespace simpledb { store_i128i128( N(simpledb), N(record3), N(simpledb), b.data(), b.size()); } - EOSLIB_SERIALIZE( insert_record3, (r3) ); + EOSLIB_SERIALIZE( insert_record3, (r3) ) }; //@abi action remove3 @@ -117,7 +117,7 @@ namespace simpledb { remove_i64i64i64( N(simpledb), N(record2), b.data()); } - EOSLIB_SERIALIZE( remove_record3, (key) ); + EOSLIB_SERIALIZE( remove_record3, (key) ) }; //@abi table @@ -125,7 +125,7 @@ namespace simpledb { std::string key; std::string value; - EOSLIB_SERIALIZE( key_value1, (key)(value) ); + EOSLIB_SERIALIZE( key_value1, (key)(value) ) }; //@abi action insertkv1 @@ -137,7 +137,7 @@ namespace simpledb { // store_str( N(simpledb), N(keyvalue1), N(simpledb), (char *)kv1.key.data(), kv1.key.size(), b.data(), b.size()); } - EOSLIB_SERIALIZE( insert_keyvalue1, (kv1) ); + EOSLIB_SERIALIZE( insert_keyvalue1, (kv1) ) }; //@abi action removekv1 @@ -148,14 +148,14 @@ namespace simpledb { //remove_str( N(simpledb), N(keyvalue1), (char *)key.data(), key.size() ); } - EOSLIB_SERIALIZE( remove_keyvalue1, (key) ); + EOSLIB_SERIALIZE( remove_keyvalue1, (key) ) }; struct complex_type { std::string name; uint64_t age; - EOSLIB_SERIALIZE( complex_type, (name)(age) ); + EOSLIB_SERIALIZE( complex_type, (name)(age) ) }; //@abi table @@ -163,7 +163,7 @@ namespace simpledb { std::string key; complex_type value; - EOSLIB_SERIALIZE( key_value2, (key)(value) ); + EOSLIB_SERIALIZE( key_value2, (key)(value) ) }; //@abi action insertkv2 @@ -175,7 +175,7 @@ namespace simpledb { // store_str( N(simpledb), N(keyvalue2), N(simpledb), (char *)kv2.key.data(), kv2.key.size(), b.data(), b.size()); } - EOSLIB_SERIALIZE( insert_keyvalue2, (kv2) ); + EOSLIB_SERIALIZE( insert_keyvalue2, (kv2) ) }; //@abi action removekv2 @@ -185,7 +185,7 @@ namespace simpledb { remove_str( N(simpledb), N(keyvalue2), (char *)key.data(), key.size() ); } - EOSLIB_SERIALIZE( remove_keyvalue2, (key) ); + EOSLIB_SERIALIZE( remove_keyvalue2, (key) ) }; template diff --git a/contracts/test_api/test_action.cpp b/contracts/test_api/test_action.cpp index 6a56f3897..5cc77f41f 100644 --- a/contracts/test_api/test_action.cpp +++ b/contracts/test_api/test_action.cpp @@ -38,11 +38,11 @@ void test_action::read_action_normal() { } void test_action::read_action_to_0() { - uint32_t total = read_action((void *)0, action_size()); + read_action((void *)0, action_size()); } void test_action::read_action_to_64k() { - uint32_t total = read_action( (void *)((1<<16)-2), action_size()); + read_action( (void *)((1<<16)-2), action_size()); } void test_action::require_notice() { diff --git a/contracts/test_api/test_api.cpp b/contracts/test_api/test_api.cpp index e35aed786..bf12f1352 100644 --- a/contracts/test_api/test_api.cpp +++ b/contracts/test_api/test_api.cpp @@ -23,7 +23,7 @@ extern "C" { } - void apply( unsigned long long code, unsigned long long action ) { + void apply( unsigned long long, unsigned long long action ) { //eosio::print("==> CONTRACT: ", code, " ", action, "\n"); //test_types WASM_TEST_HANDLER(test_types, types_size); diff --git a/contracts/test_api/test_api.hpp b/contracts/test_api/test_api.hpp index 638304ee6..595d78255 100644 --- a/contracts/test_api/test_api.hpp +++ b/contracts/test_api/test_api.hpp @@ -69,7 +69,7 @@ struct test_action { static void assert_false(); static void assert_true(); static void now(); - static void test_abort(); + static void test_abort() __attribute__ ((noreturn)) ; static void test_current_receiver(); static void test_current_sender(); static void test_publication_time(); diff --git a/contracts/test_api/test_compiler_builtins.cpp b/contracts/test_api/test_compiler_builtins.cpp index 284094adc..1492110b8 100644 --- a/contracts/test_api/test_compiler_builtins.cpp +++ b/contracts/test_api/test_compiler_builtins.cpp @@ -9,7 +9,6 @@ #include "test_api.hpp" -using namespace eosio; unsigned __int128 operator "" _ULLL( const char* lit ) { __int128 ret = 0; size_t i = 0; @@ -32,7 +31,7 @@ unsigned __int128 operator "" _ULLL( const char* lit ) { if (sign) ret *= -1; - return ret; + return (unsigned __int128)ret; } __int128 operator "" _LLL( const char* lit ) { @@ -70,28 +69,28 @@ void test_compiler_builtins::test_multi3() { __int128 lhs_b = 100; __int128 rhs_b = -30; - __multi3( res, lhs_a, ( lhs_a >> 64 ), rhs_a, ( rhs_a >> 64 ) ); + __multi3( res, uint64_t(lhs_a), uint64_t( lhs_a >> 64 ), uint64_t(rhs_a), uint64_t( rhs_a >> 64 ) ); eosio_assert( res == -3000, "__multi3 result should be -3000" ); - __multi3( res, lhs_b, ( lhs_b >> 64 ), rhs_b, ( rhs_b >> 64 ) ); + __multi3( res, uint64_t(lhs_b), uint64_t( lhs_b >> 64 ), uint64_t(rhs_b), uint64_t( rhs_b >> 64 ) ); eosio_assert( res == -3000, "__multi3 result should be -3000" ); - __multi3( res, lhs_a, ( lhs_a >> 64 ), rhs_b, ( rhs_b >> 64 ) ); + __multi3( res, uint64_t(lhs_a), uint64_t( lhs_a >> 64 ), uint64_t(rhs_b), uint64_t( rhs_b >> 64 ) ); eosio_assert( res == 900, "__multi3 result should be 900" ); /* * test for positive values */ - __multi3( res, lhs_b, ( lhs_b >> 64 ), rhs_a, ( rhs_a >> 64 ) ); + __multi3( res, uint64_t(lhs_b), uint64_t( lhs_b >> 64 ), uint64_t(rhs_a), uint64_t( rhs_a >> 64 ) ); eosio_assert( res == 10000, "__multi3 result should be 10000" ); /* * test identity */ - __multi3( res, 1, 0, rhs_a, rhs_a >> 64 ); + __multi3( res, 1, 0, uint64_t(rhs_a), uint64_t(rhs_a >> 64) ); eosio_assert( res == 100, "__multi3 result should be 100" ); - __multi3( res, 1, 0, rhs_b, rhs_b >> 64 ); + __multi3( res, 1, 0, uint64_t(rhs_b), uint64_t(rhs_b >> 64) ); eosio_assert( res == -30, "__multi3 result should be -30" ); } @@ -105,13 +104,13 @@ void test_compiler_builtins::test_divti3() { __int128 lhs_b = 100; __int128 rhs_b = -30; - __divti3( res, lhs_a, ( lhs_a >> 64 ), rhs_a, ( rhs_a >> 64 ) ); + __divti3( res, uint64_t(lhs_a), uint64_t( lhs_a >> 64 ), uint64_t(rhs_a), uint64_t( rhs_a >> 64 ) ); eosio_assert( res == 0, "__divti3 result should be 0" ); - __divti3( res, lhs_b, ( lhs_b >> 64 ), rhs_b, ( rhs_b >> 64 ) ); + __divti3( res, uint64_t(lhs_b), uint64_t( lhs_b >> 64 ), uint64_t(rhs_b), uint64_t( rhs_b >> 64 ) ); eosio_assert( res == -3, "__divti3 result should be -3" ); - __divti3( res, lhs_a, ( lhs_a >> 64 ), rhs_b, ( rhs_b >> 64 ) ); + __divti3( res, uint64_t(lhs_a), uint64_t( lhs_a >> 64 ), uint64_t(rhs_b), uint64_t( rhs_b >> 64 ) ); eosio_assert( res == 1, "__divti3 result should be 1" ); /* @@ -120,22 +119,22 @@ void test_compiler_builtins::test_divti3() { __int128 lhs_c = 3333; __int128 rhs_c = 3333; - __divti3( res, lhs_b, ( lhs_b >> 64 ), rhs_a, ( rhs_a >> 64 ) ); + __divti3( res, uint64_t(lhs_b), uint64_t( lhs_b >> 64 ), uint64_t(rhs_a), uint64_t( rhs_a >> 64 ) ); eosio_assert( res == 1, "__divti3 result should be 1" ); - __divti3( res, lhs_b, ( lhs_b >> 64 ), rhs_c, ( rhs_c >> 64 ) ); + __divti3( res, uint64_t(lhs_b), uint64_t( lhs_b >> 64 ), uint64_t(rhs_c), uint64_t( rhs_c >> 64 ) ); eosio_assert( res == 0, "__divti3 result should be 0" ); - __divti3( res, lhs_c, ( lhs_c >> 64 ), rhs_a, ( rhs_a >> 64 ) ); + __divti3( res, uint64_t(lhs_c), uint64_t( lhs_c >> 64 ), uint64_t(rhs_a), uint64_t( rhs_a >> 64 ) ); eosio_assert( res == 33, "__divti3 result should be 33" ); /* * test identity */ - __divti3( res, lhs_b, ( lhs_b >> 64 ), 1, 0 ); + __divti3( res, uint64_t(lhs_b), uint64_t( lhs_b >> 64 ), 1, 0 ); eosio_assert( res == 100, "__divti3 result should be 100" ); - __divti3( res, lhs_a, ( lhs_a >> 64 ), 1, 0 ); + __divti3( res, uint64_t(lhs_a), uint64_t( lhs_a >> 64 ), 1, 0 ); eosio_assert( res == -30, "__divti3 result should be -30" ); } @@ -147,22 +146,22 @@ void test_compiler_builtins::test_divti3_by_0() { } void test_compiler_builtins::test_udivti3() { - /* + /* * test for negative values */ unsigned __int128 res = 0; - unsigned __int128 lhs_a = -30; + unsigned __int128 lhs_a = (unsigned __int128)-30; unsigned __int128 rhs_a = 100; unsigned __int128 lhs_b = 100; - unsigned __int128 rhs_b = -30; + unsigned __int128 rhs_b = (unsigned __int128)-30; - __udivti3( res, lhs_a, ( lhs_a >> 64 ), rhs_a, ( rhs_a >> 64 ) ); + __udivti3( res, uint64_t(lhs_a), uint64_t( lhs_a >> 64 ), uint64_t(rhs_a), uint64_t( rhs_a >> 64 ) ); eosio_assert( res == 3402823669209384634633746074317682114_ULLL, "__udivti3 result should be 0" ); - __udivti3( res, lhs_b, ( lhs_b >> 64 ), rhs_b, ( rhs_b >> 64 ) ); + __udivti3( res, uint64_t(lhs_b), uint64_t( lhs_b >> 64 ), uint64_t(rhs_b), uint64_t( rhs_b >> 64 ) ); eosio_assert( res == 0, "__udivti3 result should be 0" ); - __udivti3( res, lhs_a, ( lhs_a >> 64 ), rhs_b, ( rhs_b >> 64 ) ); + __udivti3( res, uint64_t(lhs_a), uint64_t( lhs_a >> 64 ), uint64_t(rhs_b), uint64_t( rhs_b >> 64 ) ); eosio_assert( res == 1, "__udivti3 result should be 1" ); /* @@ -171,23 +170,23 @@ void test_compiler_builtins::test_udivti3() { __int128 lhs_c = 3333; __int128 rhs_c = 3333; - __udivti3( res, lhs_b, ( lhs_b >> 64 ), rhs_a, ( rhs_a >> 64 ) ); + __udivti3( res, uint64_t(lhs_b), uint64_t( lhs_b >> 64 ), uint64_t(rhs_a), uint64_t( rhs_a >> 64 ) ); eosio_assert( res == 1, "__divti3 result should be 1" ); - __udivti3( res, lhs_b, ( lhs_b >> 64 ), rhs_c, ( rhs_c >> 64 ) ); + __udivti3( res, uint64_t(lhs_b), uint64_t( lhs_b >> 64 ), uint64_t(rhs_c), uint64_t( rhs_c >> 64 ) ); eosio_assert( res == 0, "__divti3 result should be 0" ); - __udivti3( res, lhs_c, ( lhs_c >> 64 ), rhs_a, ( rhs_a >> 64 ) ); + __udivti3( res, uint64_t(lhs_c), uint64_t( lhs_c >> 64 ), uint64_t(rhs_a), uint64_t( rhs_a >> 64 ) ); eosio_assert( res == 33, "__divti3 result should be 33" ); /* * test identity */ - __udivti3( res, lhs_b, ( lhs_b >> 64 ), 1, 0 ); + __udivti3( res, uint64_t(lhs_b), uint64_t( lhs_b >> 64 ), 1, 0 ); eosio_assert( res == 100, "__divti3 result should be 100" ); - __udivti3( res, lhs_a, ( lhs_a >> 64 ), 1, 0 ); - eosio_assert( res == -30, "__divti3 result should be -30" ); + __udivti3( res, uint64_t(lhs_a), uint64_t( lhs_a >> 64 ), 1, 0 ); + eosio_assert( res == (unsigned __int128)-30, "__divti3 result should be -30" ); } void test_compiler_builtins::test_udivti3_by_0() { @@ -207,27 +206,27 @@ void test_compiler_builtins::test_lshlti3() { test_res <<= 1; - __lshlti3( res, val, val >> 64, 0 ); + __lshlti3( res, uint64_t(val), uint64_t(val >> 64), 0 ); eosio_assert( res == 1, "__lshlti3 result should be 1" ); - __lshlti3( res, val, val >> 64, 1 ); + __lshlti3( res, uint64_t(val), uint64_t(val >> 64), 1 ); eosio_assert( res == ( 1 << 1 ), "__lshlti3 result should be 2" ); - __lshlti3( res, val, ( val >> 64 ), 31 ); - eosio_assert( res == 2147483648_ULLL, "__lshlti3 result should be 2^31" ); + __lshlti3( res, uint64_t(val), uint64_t( val >> 64 ), 31 ); + eosio_assert( (unsigned __int128)res == 2147483648_ULLL, "__lshlti3 result should be 2^31" ); - __lshlti3( res, val, ( val >> 64 ), 63 ); - eosio_assert( res == 9223372036854775808_ULLL, "__lshlti3 result should be 2^63" ); + __lshlti3( res, uint64_t(val), uint64_t( val >> 64 ), 63 ); + eosio_assert( (unsigned __int128)res == 9223372036854775808_ULLL, "__lshlti3 result should be 2^63" ); - __lshlti3( res, val, ( val >> 64 ), 64 ); + __lshlti3( res, uint64_t(val), uint64_t( val >> 64 ), 64 ); eosio_assert( res == test_res, "__lshlti3 result should be 2^64" ); - __lshlti3( res, val, ( val >> 64 ), 127 ); + __lshlti3( res, uint64_t(val), uint64_t( val >> 64 ), 127 ); test_res <<= 63; eosio_assert( res == test_res, "__lshlti3 result should be 2^127" ); - __lshlti3( res, val, ( val >> 64 ), 128 ); + __lshlti3( res, uint64_t(val), uint64_t( val >> 64 ), 128 ); test_res <<= 1; //should rollover eosio_assert( res == test_res, "__lshlti3 result should be 2^128" ); @@ -241,27 +240,27 @@ void test_compiler_builtins::test_ashlti3() { test_res = 0x8000000000000000; test_res <<= 1; - __ashlti3( res, val, val >> 64, 0 ); + __ashlti3( res, uint64_t(val), uint64_t(val >> 64), 0 ); eosio_assert( res == 1, "__ashlti3 result should be 1" ); - __ashlti3( res, val, val >> 64, 1 ); + __ashlti3( res, uint64_t(val), uint64_t(val >> 64), 1 ); eosio_assert( res == (1 << 1), "__ashlti3 result should be 2" ); - __ashlti3( res, val, (val >> 64), 31 ); - eosio_assert( res == 2147483648_ULLL, "__ashlti3 result should be 2^31" ); + __ashlti3( res, uint64_t(val), uint64_t(val >> 64), 31 ); + eosio_assert( res == (__int128)2147483648_ULLL, "__ashlti3 result should be 2^31" ); - __ashlti3( res, val, (val >> 64), 63 ); - eosio_assert( res == 9223372036854775808_ULLL, "__ashlti3 result should be 2^63" ); + __ashlti3( res, uint64_t(val), uint64_t(val >> 64), 63 ); + eosio_assert( res == (__int128)9223372036854775808_ULLL, "__ashlti3 result should be 2^63" ); - __ashlti3( res, val, (val >> 64), 64 ); + __ashlti3( res, uint64_t(val), uint64_t(val >> 64), 64 ); eosio_assert( res == test_res, "__ashlti3 result should be 2^64" ); - __ashlti3( res, val, (val >> 64), 127 ); + __ashlti3( res, uint64_t(val), uint64_t(val >> 64), 127 ); test_res <<= 63; eosio_assert( res == test_res, "__ashlti3 result should be 2^127" ); - __ashlti3( res, val, (val >> 64), 128 ); + __ashlti3( res, uint64_t(val), uint64_t(val >> 64), 128 ); test_res <<= 1; //should rollover eosio_assert( res == test_res, "__ashlti3 result should be 2^128" ); @@ -276,22 +275,22 @@ void test_compiler_builtins::test_lshrti3() { val <<= 64; test_res <<= 64; - __lshrti3( res, val, (val >> 64), 0 ); + __lshrti3( res, uint64_t(val), uint64_t(val >> 64), 0 ); eosio_assert( res == test_res, "__lshrti3 result should be 2^127" ); - __lshrti3( res, val, (val >> 64), 1 ); - eosio_assert( res == 85070591730234615865843651857942052864_ULLL, "__lshrti3 result should be 2^126" ); + __lshrti3( res, uint64_t(val), uint64_t(val >> 64), 1 ); + eosio_assert( res == (__int128)85070591730234615865843651857942052864_ULLL, "__lshrti3 result should be 2^126" ); - __lshrti3( res, val, (val >> 64), 63 ); - eosio_assert( res == 18446744073709551616_ULLL, "__lshrti3 result should be 2^64" ); + __lshrti3( res, uint64_t(val), uint64_t(val >> 64), 63 ); + eosio_assert( res == (__int128)18446744073709551616_ULLL, "__lshrti3 result should be 2^64" ); - __lshrti3( res, val, (val >> 64), 64 ); - eosio_assert( res == 9223372036854775808_ULLL, "__lshrti3 result should be 2^63" ); + __lshrti3( res, uint64_t(val), uint64_t(val >> 64), 64 ); + eosio_assert( res == (__int128)9223372036854775808_ULLL, "__lshrti3 result should be 2^63" ); - __lshrti3( res, val, (val >> 64), 96 ); - eosio_assert( res == 2147483648_ULLL, "__lshrti3 result should be 2^31" ); + __lshrti3( res, uint64_t(val), uint64_t(val >> 64), 96 ); + eosio_assert( res == (__int128)2147483648_ULLL, "__lshrti3 result should be 2^31" ); - __lshrti3( res, val, (val >> 64), 127 ); + __lshrti3( res, uint64_t(val), uint64_t(val >> 64), 127 ); eosio_assert( res == 0x1, "__lshrti3 result should be 2^0" ); } @@ -302,22 +301,22 @@ void test_compiler_builtins::test_ashrti3() { test <<= 127; - __ashrti3( res, val, (val >> 64), 0 ); + __ashrti3( res, uint64_t(val), uint64_t(val >> 64), 0 ); eosio_assert( res == -170141183460469231731687303715884105728_LLL, "__ashrti3 result should be -2^127" ); - __ashrti3(res, val, (val >> 64), 1 ); + __ashrti3(res, uint64_t(val), uint64_t(val >> 64), 1 ); eosio_assert( res == -85070591730234615865843651857942052864_LLL, "__ashrti3 result should be -2^126" ); - __ashrti3(res, val, (val >> 64), 2 ); + __ashrti3(res, uint64_t(val), uint64_t(val >> 64), 2 ); eosio_assert( res == test >> 2, "__ashrti3 result should be -2^125" ); - __ashrti3( res, val, (val >> 64), 64 ); + __ashrti3( res, uint64_t(val), uint64_t(val >> 64), 64 ); eosio_assert( res == test >> 64, "__ashrti3 result should be -2^63" ); - __ashrti3( res, val, (val >> 64), 95 ); + __ashrti3( res, uint64_t(val), uint64_t(val >> 64), 95 ); eosio_assert( res == test >> 95, "__ashrti3 result should be -2^31" ); - __ashrti3( res, val, (val >> 64), 127 ); + __ashrti3( res, uint64_t(val), uint64_t(val >> 64), 127 ); eosio_assert( res == test >> 127, "__ashrti3 result should be -2^0" ); } @@ -329,25 +328,25 @@ void test_compiler_builtins::test_modti3() { __int128 lhs_b = 30; __int128 rhs_b = -100; - __modti3( res, lhs_a, lhs_a >> 64, rhs_a, rhs_a >> 64 ); + __modti3( res, uint64_t(lhs_a), uint64_t(lhs_a >> 64), uint64_t(rhs_a), uint64_t(rhs_a >> 64) ); eosio_assert( res == -30, "__modti3 result should be -30" ); - __modti3( res, lhs_b, lhs_b >> 64, rhs_b, rhs_b >> 64 ); + __modti3( res, uint64_t(lhs_b), uint64_t(lhs_b >> 64), uint64_t(rhs_b), uint64_t(rhs_b >> 64) ); eosio_assert( res == 30, "__modti3 result should be 30" ); - __modti3( res, lhs_a, lhs_a >> 64, rhs_b, rhs_b >> 64 ); + __modti3( res, uint64_t(lhs_a), uint64_t(lhs_a >> 64), uint64_t(rhs_b), uint64_t(rhs_b >> 64) ); eosio_assert( res == -30, "__modti3 result should be -30" ); - __modti3( res, rhs_a, rhs_a >> 64, lhs_b, lhs_b >> 64 ); + __modti3( res, uint64_t(rhs_a), uint64_t(rhs_a >> 64), uint64_t(lhs_b), uint64_t(lhs_b >> 64) ); eosio_assert( res == 10, "__modti3 result should be 10" ); - __modti3( res, rhs_a, rhs_a >> 64, rhs_b, rhs_b >> 64 ); + __modti3( res, uint64_t(rhs_a), uint64_t(rhs_a >> 64), uint64_t(rhs_b), uint64_t(rhs_b >> 64) ); eosio_assert( res == 0, "__modti3 result should be 0" ); - __modti3( res, rhs_a, rhs_a >> 64, rhs_a, rhs_a >> 64 ); + __modti3( res, uint64_t(rhs_a), uint64_t(rhs_a >> 64), uint64_t(rhs_a), uint64_t(rhs_a >> 64) ); eosio_assert( res == 0, "__modti3 result should be 0" ); - __modti3( res, 0, 0, rhs_a, rhs_a >> 64 ); + __modti3( res, 0, 0, uint64_t(rhs_a), uint64_t(rhs_a >> 64) ); eosio_assert( res == 0, "__modti3 result should be 0" ); } @@ -355,36 +354,36 @@ void test_compiler_builtins::test_modti3_by_0() { __int128 res = 0; __int128 lhs = 100; - __modti3( res, lhs, lhs >> 64, 0, 0 ); + __modti3( res, uint64_t(lhs), uint64_t(lhs >> 64), 0, 0 ); eosio_assert( false, "should have thrown an error" ); } void test_compiler_builtins::test_umodti3() { unsigned __int128 res = 0; - unsigned __int128 lhs_a = -30; + unsigned __int128 lhs_a = (unsigned __int128)-30; unsigned __int128 rhs_a = 100; unsigned __int128 lhs_b = 30; - unsigned __int128 rhs_b = -100; + unsigned __int128 rhs_b = (unsigned __int128)-100; - __umodti3( res, lhs_a, lhs_a >> 64, rhs_a, rhs_a >> 64 ); - eosio_assert( res == -30, "__modti3 result should be -30" ); + __umodti3( res, uint64_t(lhs_a), uint64_t(lhs_a >> 64), uint64_t(rhs_a), uint64_t(rhs_a >> 64) ); + eosio_assert( res == (unsigned __int128)-30, "__modti3 result should be -30" ); - __umodti3( res, lhs_b, lhs_b >> 64, rhs_b, rhs_b >> 64 ); + __umodti3( res, uint64_t(lhs_b), uint64_t(lhs_b >> 64), uint64_t(rhs_b), uint64_t(rhs_b >> 64) ); eosio_assert( res == 30, "__modti3 result should be 30" ); - __umodti3( res, lhs_a, lhs_a >> 64, rhs_b, rhs_b >> 64 ); - eosio_assert( res == -30, "__modti3 result should be -30" ); + __umodti3( res, uint64_t(lhs_a), uint64_t(lhs_a >> 64), uint64_t(rhs_b), uint64_t(rhs_b >> 64) ); + eosio_assert( res == (unsigned __int128)-30, "__modti3 result should be -30" ); - __umodti3( res, rhs_a, rhs_a >> 64, lhs_b, lhs_b >> 64 ); + __umodti3( res, uint64_t(rhs_a), uint64_t(rhs_a >> 64), uint64_t(lhs_b), uint64_t(lhs_b >> 64) ); eosio_assert( res == 10, "__modti3 result should be 10" ); - __umodti3( res, rhs_a, rhs_a >> 64, rhs_b, rhs_b >> 64 ); + __umodti3( res, uint64_t(rhs_a), uint64_t(rhs_a >> 64), uint64_t(rhs_b), uint64_t(rhs_b >> 64) ); eosio_assert( res == 0, "__modti3 result should be 0" ); - __umodti3( res, rhs_a, rhs_a >> 64, rhs_a, rhs_a >> 64 ); + __umodti3( res, uint64_t(rhs_a), uint64_t(rhs_a >> 64), uint64_t(rhs_a), uint64_t(rhs_a >> 64) ); eosio_assert( res == 0, "__modti3 result should be 0" ); - __umodti3( res, 0, 0, rhs_a, rhs_a >> 64 ); + __umodti3( res, 0, 0, uint64_t(rhs_a), uint64_t(rhs_a >> 64) ); eosio_assert( res == 0, "__modti3 result should be 0" ); } @@ -392,6 +391,6 @@ void test_compiler_builtins::test_umodti3_by_0() { unsigned __int128 res = 0; unsigned __int128 lhs = 100; - __umodti3( res, lhs, lhs >> 64, 0, 0 ); + __umodti3( res, uint64_t(lhs), uint64_t(lhs >> 64), 0, 0 ); eosio_assert( false, "should have thrown an error" ); } diff --git a/contracts/test_api/test_crypto.cpp b/contracts/test_api/test_crypto.cpp index ce703a0d6..508f0d568 100644 --- a/contracts/test_api/test_crypto.cpp +++ b/contracts/test_api/test_crypto.cpp @@ -193,24 +193,23 @@ struct sig_hash_key { void test_crypto::test_recover_key_assert_true() { sig_hash_key sh; - int read = read_action( (char*)&sh, sizeof(sh) ); - public_key public_key; + read_action( (char*)&sh, sizeof(sh) ); assert_recover_key( &sh.hash, (const char*)&sh.sig, sizeof(sh.sig), (const char*)&sh.pk, sizeof(sh.pk) ); } void test_crypto::test_recover_key_assert_false() { sig_hash_key sh; - int read = read_action( (char*)&sh, sizeof(sh) ); + read_action( (char*)&sh, sizeof(sh) ); assert_recover_key( &sh.hash, (const char*)&sh.sig, sizeof(sh.sig), (const char*)&sh.pk, sizeof(sh.pk) ); eosio_assert( false, "should have thrown an error" ); } void test_crypto::test_recover_key() { sig_hash_key sh; - int read = read_action( (char*)&sh, sizeof(sh) ); + read_action( (char*)&sh, sizeof(sh) ); public_key pk; - int recovered = recover_key( &sh.hash, (const char*)&sh.sig, sizeof(sh.sig), pk.data, sizeof(pk) ); - for ( int i=0; i < sizeof(pk); i++ ) + recover_key( &sh.hash, (const char*)&sh.sig, sizeof(sh.sig), pk.data, sizeof(pk) ); + for ( uint32_t i=0; i < sizeof(pk); i++ ) if ( pk.data[i] != sh.pk.data[i] ) eosio_assert( false, "public key does not match" ); } @@ -284,8 +283,6 @@ void test_crypto::test_ripemd160() { void test_crypto::sha256_null() { checksum256 tmp; - int a = 3; - int* b = &a; sha256(nullptr, 100, &tmp); //eosio_assert(false, "should've thrown an error"); } diff --git a/contracts/test_api/test_fixedpoint.cpp b/contracts/test_api/test_fixedpoint.cpp index 0a0f163b5..3f7c02607 100644 --- a/contracts/test_api/test_fixedpoint.cpp +++ b/contracts/test_api/test_fixedpoint.cpp @@ -2,85 +2,85 @@ #include #include "test_api.hpp" -using namespace eosio; + void test_fixedpoint::create_instances() { { // Various ways to create fixed_point128 - fixed_point128<18> a(12345667); - fixed_point128<18> b(12345667); - fixed_point128<16> c(12345667); - eosio_assert(b == a, "fixed_point128 instances comparison with same number of decimals"); - eosio_assert(c == a, "fixed_point128 instances with different number of decimals"); + eosio::fixed_point128<18> a(12345667); + eosio::fixed_point128<18> b(12345667); + eosio::fixed_point128<16> c(12345667); + eosio_assert(b == a, "fixed_point128 instances comparison with same number of decimals"); + eosio_assert(c == a, "fixed_point128 instances with different number of decimals"); } { // Various ways to create fixed_point64 - fixed_point64<5> a(12345667); - fixed_point64<5> b(12345667); - fixed_point64<5> c(12345667); - eosio_assert(b == a, "fixed_point64 instances comparison with same number of decimals"); - eosio_assert(c == a, "fixed_point64 instances with different number of decimals"); + eosio::fixed_point64<5> a(12345667); + eosio::fixed_point64<5> b(12345667); + eosio::fixed_point64<5> c(12345667); + eosio_assert(b == a, "fixed_point64 instances comparison with same number of decimals"); + eosio_assert(c == a, "fixed_point64 instances with different number of decimals"); } { // Various ways to create fixed_point32 - fixed_point32<18> a(12345667); - fixed_point32<18> b(12345667); - fixed_point32<16> c(12345667); - eosio_assert(b == a, "fixed_point32 instances comparison with same number of decimals"); - eosio_assert(c == a, "fixed_point32 instances with different number of decimals"); + eosio::fixed_point32<18> a(12345667); + eosio::fixed_point32<18> b(12345667); + eosio::fixed_point32<16> c(12345667); + eosio_assert(b == a, "fixed_point32 instances comparison with same number of decimals"); + eosio_assert(c == a, "fixed_point32 instances with different number of decimals"); } } void test_fixedpoint::test_addition() { { - // Various ways to create fixed_point32 - fixed_point32<0> a(100); - fixed_point32<0> b(100); - fixed_point32<0> c = a + b; - fixed_point32<0> d = 200; - eosio_assert(c == d, "fixed_point32 instances addition with zero decmimals"); + // Various ways to create fixed_point32 + eosio::fixed_point32<0> a(100); + eosio::fixed_point32<0> b(100); + eosio::fixed_point32<0> c = a + b; + eosio::fixed_point32<0> d = 200; + eosio_assert(c == d, "fixed_point32 instances addition with zero decmimals"); } { - // Various ways to create fixed_point64 - fixed_point64<0> a(100); - fixed_point64<0> b(100); - fixed_point64<0> c = a + b; - fixed_point64<0> d = 200; - eosio_assert(c == d, "fixed_point64 instances addition with zero decmimals"); + // Various ways to create fixed_point64 + eosio::fixed_point64<0> a(100); + eosio::fixed_point64<0> b(100); + eosio::fixed_point64<0> c = a + b; + eosio::fixed_point64<0> d = 200; + eosio_assert(c == d, "fixed_point64 instances addition with zero decmimals"); } }; void test_fixedpoint::test_subtraction() { { - // Various ways to create fixed_point64 - fixed_point64<0> a(100); - fixed_point64<0> b(100); - fixed_point64<0> c = a - b; - fixed_point64<0> d = 0; - eosio_assert(c == d, "fixed_point64 instances subtraction with zero decmimals"); - - fixed_point64<0> a1(0); - fixed_point64<0> c1 = a1 - b; - fixed_point64<0> d1 = -100; - eosio_assert(c1 == d1, "fixed_point64 instances subtraction with zero decmimals"); + // Various ways to create fixed_point64 + eosio::fixed_point64<0> a(100); + eosio::fixed_point64<0> b(100); + eosio::fixed_point64<0> c = a - b; + eosio::fixed_point64<0> d = 0; + eosio_assert(c == d, "fixed_point64 instances subtraction with zero decmimals"); + + eosio::fixed_point64<0> a1(0); + eosio::fixed_point64<0> c1 = a1 - b; + eosio::fixed_point64<0> d1 = -100; + eosio_assert(c1 == d1, "fixed_point64 instances subtraction with zero decmimals"); } { - // Various ways to create fixed_point32 - fixed_point32<0> a(100); - fixed_point32<0> b(100); - fixed_point32<0> c = a - b; - fixed_point32<0> d = 0; - eosio_assert(c == d, "fixed_point32 instances subtraction with zero decmimals"); - - // Various ways to create fixed_point32 - fixed_point32<0> a1(0); - fixed_point32<0> c1 = a1 - b; - fixed_point32<0> d1 = -100; - eosio_assert(c1 == d1, "fixed_point32 instances subtraction with zero decmimals"); + // Various ways to create fixed_point32 + eosio::fixed_point32<0> a(100); + eosio::fixed_point32<0> b(100); + eosio::fixed_point32<0> c = a - b; + eosio::fixed_point32<0> d = 0; + eosio_assert(c == d, "fixed_point32 instances subtraction with zero decmimals"); + + // Various ways to create fixed_point32 + eosio::fixed_point32<0> a1(0); + eosio::fixed_point32<0> c1 = a1 - b; + eosio::fixed_point32<0> d1 = -100; + eosio_assert(c1 == d1, "fixed_point32 instances subtraction with zero decmimals"); } }; @@ -88,21 +88,21 @@ void test_fixedpoint::test_subtraction() void test_fixedpoint::test_multiplication() { { - // Various ways to create fixed_point64 - fixed_point64<0> a(100); - fixed_point64<0> b(200); - fixed_point128<0> c = a * b; - fixed_point128<0> d(200*100); - eosio_assert(c == d, "fixed_point64 instances multiplication result in fixed_point128"); + // Various ways to create fixed_point64 + eosio::fixed_point64<0> a(100); + eosio::fixed_point64<0> b(200); + eosio::fixed_point128<0> c = a * b; + eosio::fixed_point128<0> d(200*100); + eosio_assert(c == d, "fixed_point64 instances multiplication result in fixed_point128"); } { - // Various ways to create fixed_point32 - fixed_point32<0> a(100); - fixed_point32<0> b(200); - fixed_point64<0> c = a * b; - fixed_point64<0> d(200*100); - eosio_assert(c == d, "fixed_point32 instances multiplication result in fixed_point64"); + // Various ways to create fixed_point32 + eosio::fixed_point32<0> a(100); + eosio::fixed_point32<0> b(200); + eosio::fixed_point64<0> c = a * b; + eosio::fixed_point64<0> d(200*100); + eosio_assert(c == d, "fixed_point32 instances multiplication result in fixed_point64"); } } @@ -112,11 +112,11 @@ void test_fixedpoint::test_division() uint64_t lhs = 10000000; uint64_t rhs = 333; - fixed_point64<0> a(lhs); - fixed_point64<0> b(rhs); - fixed_point128<5> c = a / b; + eosio::fixed_point64<0> a((int64_t)lhs); + eosio::fixed_point64<0> b((int64_t)rhs); + eosio::fixed_point128<5> c = a / b; - fixed_point128<5> e = fixed_divide<5>(lhs, rhs); + eosio::fixed_point128<5> e = eosio::fixed_divide<5>(lhs, rhs); print(e); eosio_assert(c == e, "fixed_point64 instances division result from operator and function and compare in fixed_point128"); @@ -126,11 +126,11 @@ void test_fixedpoint::test_division() uint32_t lhs = 100000; uint32_t rhs = 33; - fixed_point32<0> a(lhs); - fixed_point32<0> b(rhs); - fixed_point64<5> c = a / b; + eosio::fixed_point32<0> a((int32_t)lhs); + eosio::fixed_point32<0> b((int32_t)rhs); + eosio::fixed_point64<5> c = a / b; - fixed_point64<5> e = fixed_divide<5>(lhs, rhs); + eosio::fixed_point64<5> e = eosio::fixed_divide<5>(lhs, rhs); eosio_assert(c == e, "fixed_point64 instances division result from operator and function and compare in fixed_point128"); } @@ -142,10 +142,12 @@ void test_fixedpoint::test_division_by_0() uint64_t lhs = 10000000; uint64_t rhs = 0; - fixed_point64<0> a(lhs); - fixed_point64<0> b(rhs); + eosio::fixed_point64<0> a((int64_t)lhs); + eosio::fixed_point64<0> b((int64_t)rhs); - fixed_point128<5> e = fixed_divide<5>(lhs, rhs); + eosio::fixed_point128<5> e = eosio::fixed_divide<5>(lhs, rhs); + // in order to get rid of unused parameter warning + e = 0; eosio_assert(false, "should've thrown an error"); } diff --git a/contracts/test_api/test_math.cpp b/contracts/test_api/test_math.cpp index f080474b4..7b4313877 100644 --- a/contracts/test_api/test_math.cpp +++ b/contracts/test_api/test_math.cpp @@ -4,8 +4,6 @@ #include "test_api.hpp" -using namespace eosio; - void test_math::test_multeq() { u128_action act; auto n = read_action(&act, sizeof(u128_action)); @@ -44,13 +42,13 @@ void test_math::test_i64_to_double() uint64_t d = i64_to_double(2); eosio_assert(i[0] == d, "test_i64_to_double i[0] == d"); - d = i64_to_double(-2); + d = i64_to_double(uint64_t(-2)); eosio_assert(i[1] == d, "test_i64_to_double i[1] == d"); d = i64_to_double(100000); eosio_assert(i[2] == d, "test_i64_to_double i[2] == d"); - d = i64_to_double(-100000); + d = i64_to_double(uint64_t(-100000)); eosio_assert(i[3] == d, "test_i64_to_double i[3] == d"); d = i64_to_double(0); @@ -62,19 +60,19 @@ void test_math::test_double_to_i64() uint64_t d[4]; read_action(&d, sizeof(d)); - int64_t i = double_to_i64(d[0]); + int64_t i = (int64_t)double_to_i64(d[0]); eosio_assert(2 == i, "test_double_to_i64 2 == i"); - i = double_to_i64(d[1]); + i = (int64_t)double_to_i64(d[1]); eosio_assert(-2 == i, "test_double_to_i64 -2 == i"); - i = double_to_i64(d[2]); + i = (int64_t)double_to_i64(d[2]); eosio_assert(100000 == i, "test_double_to_i64 100000 == i"); - i = double_to_i64(d[3]); + i = (int64_t)double_to_i64(d[3]); eosio_assert(-100000 == i, "test_double_to_i64 -100000 == i"); - i = double_to_i64(0); + i = (int64_t)double_to_i64(0); eosio_assert(0 == i, "test_double_to_i64 0 == i"); } @@ -112,7 +110,7 @@ void test_math::test_double_api() { void test_math::test_double_api_div_0() { double_div( i64_to_double(1), double_add( - i64_to_double(-5), i64_to_double(5) + i64_to_double((uint64_t)-5), i64_to_double(5) )); eosio_assert(false, "should've thrown an error"); diff --git a/contracts/test_api/test_print.cpp b/contracts/test_api/test_print.cpp index fe2ba0477..a9287631d 100644 --- a/contracts/test_api/test_print.cpp +++ b/contracts/test_api/test_print.cpp @@ -5,7 +5,8 @@ #include #include "test_api.hpp" -using namespace eosio; + +//using namespace eosio; void test_print::test_prints_l() { char ab[] = { 'a', 'b' }; @@ -17,22 +18,22 @@ void test_print::test_prints_l() { } void test_print::test_prints() { - prints("ab"); - prints(nullptr); - prints("c\0test_prints"); - prints(0); - prints("efg"); - prints(0); + prints("ab"); + prints(nullptr); + prints("c\0test_prints"); + prints(0); + prints("efg"); + prints(0); } void test_print::test_printi() { - printi(0); - printi(556644); - printi(-1); + printi(0); + printi(556644); + printi((uint64_t)-1); } void test_print::test_printi128() { - uint128_t a(-1); + uint128_t a((uint128_t)-1); uint128_t b(0); uint128_t c(87654323456); printi128(&a); @@ -41,14 +42,14 @@ void test_print::test_printi128() { } void test_print::test_printn() { - printn(N(abcde)); - printn(N(abBde)); - printn(N(1q1q1qAA)); - printn(N()); - printn(N(AAAAAA)); - printn(N(abcdefghijk)); - printn(N(abcdefghijkl)); - printn(N(abcdefghijkl1)); - printn(N(abcdefghijkl12)); - printn(N(abcdefghijkl123)); + printn(N(abcde)); + printn(N(abBde)); + printn(N(1q1q1qAA)); + printn(N()); + printn(N(AAAAAA)); + printn(N(abcdefghijk)); + printn(N(abcdefghijkl)); + printn(N(abcdefghijkl1)); + printn(N(abcdefghijkl12)); + printn(N(abcdefghijkl123)); } diff --git a/contracts/test_api/test_real.cpp b/contracts/test_api/test_real.cpp index a2a1bed47..fcb54698b 100644 --- a/contracts/test_api/test_real.cpp +++ b/contracts/test_api/test_real.cpp @@ -2,7 +2,9 @@ #include #include "test_api.hpp" + using namespace eosio; + void test_real::create_instances() { real lhs1(5); eosio_assert(lhs1.value() == 5, "real instance value is wrong"); @@ -21,6 +23,8 @@ void test_real::test_division_by_0() { real lhs1(5); real rhs1(0); real result1 = lhs1 / rhs1; + // in order to get rid of unused parameter warning + result1 = 0; eosio_assert(false, "should've thrown an error"); } diff --git a/contracts/test_api/test_transaction.cpp b/contracts/test_api/test_transaction.cpp index 6ec784d73..bf08fff9b 100644 --- a/contracts/test_api/test_transaction.cpp +++ b/contracts/test_api/test_transaction.cpp @@ -19,7 +19,7 @@ struct test_action_action { return action_name(NAME); } - vector data; + eosio::vector data; template friend DataStream& operator << ( DataStream& ds, const test_action_action& a ) { @@ -35,6 +35,7 @@ struct test_action_action { */ }; + template struct test_dummy_action { static account_name get_account() { @@ -49,38 +50,38 @@ struct test_dummy_action { int32_t c; template - friend DataStream& operator << ( DataStream& ds, const test_dummy_action& a ) { - ds << a.a; - ds << a.b; - ds << a.c; + friend DataStream& operator << ( DataStream& ds, const test_dummy_action& da ) { + ds << da.a; + ds << da.b; + ds << da.c; return ds; } template - friend DataStream& operator >> ( DataStream& ds, test_dummy_action& a ) { - ds >> a.a; - ds >> a.b; - ds >> a.c; + friend DataStream& operator >> ( DataStream& ds, test_dummy_action& da ) { + ds >> da.a; + ds >> da.b; + ds >> da.c; return ds; } }; #pragma pack(pop) -void copy_data(char* data, size_t data_len, vector& data_out) { - for (int i=0; i < data_len; i++) +void copy_data(char* data, size_t data_len, eosio::vector& data_out) { + for (unsigned int i=0; i < data_len; i++) data_out.push_back(data[i]); } void test_transaction::send_action() { test_dummy_action test_action = {DUMMY_ACTION_DEFAULT_A, DUMMY_ACTION_DEFAULT_B, DUMMY_ACTION_DEFAULT_C}; - action act(vector{{N(testapi), N(active)}}, test_action); + action act(eosio::vector{{N(testapi), N(active)}}, test_action); act.send(); } void test_transaction::send_action_empty() { test_action_action test_action; - action act(vector{{N(testapi), N(active)}}, test_action); + action act(eosio::vector{{N(testapi), N(active)}}, test_action); act.send(); } @@ -102,7 +103,7 @@ void test_transaction::send_action_large() { */ void test_transaction::send_action_recurse() { char buffer[1024]; - uint32_t size = read_action(buffer, 1024); + read_action(buffer, 1024); test_action_action test_action; copy_data(buffer, 1024, test_action.data); @@ -139,7 +140,7 @@ void test_transaction::test_read_transaction() { checksum256 h; transaction t; char* p = (char*)&t; - uint64_t read = read_transaction( (char*)&t, sizeof(t) ); + uint32_t read = read_transaction( (char*)&t, sizeof(t) ); sha256(p, read, &h); printhex( &h, sizeof(h) ); } diff --git a/contracts/test_api/test_types.cpp b/contracts/test_api/test_types.cpp index 56d57f108..53e1a0718 100644 --- a/contracts/test_api/test_types.cpp +++ b/contracts/test_api/test_types.cpp @@ -20,7 +20,7 @@ void test_types::types_size() { eosio_assert( sizeof(token_name) == 8, "token_name size != 8"); eosio_assert( sizeof(table_name) == 8, "table_name size != 8"); eosio_assert( sizeof(time) == 4, "time size != 4"); - eosio_assert( sizeof(key256) == 32, "key256 size != 32" ); + eosio_assert( sizeof(eosio::key256) == 32, "key256 size != 32" ); } void test_types::char_to_symbol() { @@ -59,7 +59,7 @@ void test_types::char_to_symbol() { for(unsigned char i = 0; i<255; i++) { if((i >= 'a' && i <= 'z') || (i >= '1' || i <= '5')) continue; - eosio_assert( eosio::char_to_symbol(i) == 0, "eosio::char_to_symbol() != 0"); + eosio_assert( eosio::char_to_symbol((char)i) == 0, "eosio::char_to_symbol() != 0"); } } diff --git a/contracts/test_api_db/test_db.cpp b/contracts/test_api_db/test_db.cpp index 423450021..62f72d64b 100644 --- a/contracts/test_api_db/test_db.cpp +++ b/contracts/test_api_db/test_db.cpp @@ -62,7 +62,7 @@ struct TestModel3xi64_V2 : TestModel3xi64 { extern "C" { void my_memset(void *vptr, unsigned char val, unsigned int size) { char *ptr = (char *)vptr; - while(size--) { *(ptr++)=val; } + while(size--) { *(ptr++)=(char)val; } } uint32_t my_strlen(const char *str) { uint32_t len = 0; @@ -187,7 +187,7 @@ void test_db::key_str_general() { const char* atr[] = { "atr", "atr", "atr", "atr" }; const char* ztr[] = { "ztr", "ztr", "ztr", "ztr" }; - uint32_t res=0; + int32_t res=0; //fill some data in contiguous tables for(int i=0; i < 4; ++i) { @@ -214,46 +214,46 @@ void test_db::key_str_general() { res = load_str(current_receiver(), current_receiver(), N(str), (char *)keys[0], STRLEN(keys[0]), tmp, 64); - eosio_assert(res == STRLEN(vals[0]) && my_memcmp((void *)vals[0], (void *)tmp, res), "load alice"); + eosio_assert(uint32_t(res) == STRLEN(vals[0]) && my_memcmp((void *)vals[0], (void *)tmp, uint32_t(res)), "load alice"); res = load_str(current_receiver(), current_receiver(), N(str), (char *)keys[1], STRLEN(keys[1]), tmp, 64); - eosio_assert(res == STRLEN(vals[1]) && my_memcmp((void *)vals[1], (void *)tmp, res), "load bob"); + eosio_assert(uint32_t(res) == STRLEN(vals[1]) && my_memcmp((void *)vals[1], (void *)tmp, uint32_t(res)), "load bob"); res = load_str(current_receiver(), current_receiver(), N(str), (char *)keys[2], STRLEN(keys[2]), tmp, 64); - eosio_assert(res == STRLEN(vals[2]) && my_memcmp((void *)vals[2], (void *)tmp, res), "load carol"); + eosio_assert(uint32_t(res) == STRLEN(vals[2]) && my_memcmp((void *)vals[2], (void *)tmp, uint32_t(res)), "load carol"); res = load_str(current_receiver(), current_receiver(), N(str), (char *)keys[3], STRLEN(keys[3]), tmp, 64); - eosio_assert(res == STRLEN(vals[3]) && my_memcmp((void *)vals[3], (void *)tmp, res), "load dave"); + eosio_assert(uint32_t(res) == STRLEN(vals[3]) && my_memcmp((void *)vals[3], (void *)tmp, uint32_t(res)), "load dave"); res = previous_str(current_receiver(), current_receiver(), N(str), (char *)keys[3], STRLEN(keys[3]), tmp, 64); - eosio_assert(res == STRLEN(vals[2]) && my_memcmp((void *)vals[2], (void *)tmp, res), "back carol"); + eosio_assert(uint32_t(res) == STRLEN(vals[2]) && my_memcmp((void *)vals[2], (void *)tmp, uint32_t(res)), "back carol"); res = previous_str(current_receiver(), current_receiver(), N(str), (char *)keys[2], STRLEN(keys[2]), tmp, 64); - eosio_assert(res == STRLEN(vals[1]) && my_memcmp((void *)vals[1], (void *)tmp, res), "back dave"); + eosio_assert(uint32_t(res) == STRLEN(vals[1]) && my_memcmp((void *)vals[1], (void *)tmp, uint32_t(res)), "back dave"); res = previous_str(current_receiver(), current_receiver(), N(str), (char *)keys[1], STRLEN(keys[1]), tmp, 64); - eosio_assert(res == STRLEN(vals[0]) && my_memcmp((void *)vals[0], (void *)tmp, res), "back alice"); + eosio_assert(uint32_t(res) == STRLEN(vals[0]) && my_memcmp((void *)vals[0], (void *)tmp, uint32_t(res)), "back alice"); res = previous_str(current_receiver(), current_receiver(), N(str), (char *)keys[0], STRLEN(keys[0]), tmp, 64); eosio_assert(res == 0, "no prev"); res = next_str(current_receiver(), current_receiver(), N(str), (char *)keys[0], STRLEN(keys[0]), tmp, 64); - eosio_assert(res == STRLEN(vals[1]) && my_memcmp((void *)vals[1], (void *)tmp, res), "next bob"); + eosio_assert(uint32_t(res) == STRLEN(vals[1]) && my_memcmp((void *)vals[1], (void *)tmp, uint32_t(res)), "next bob"); res = next_str(current_receiver(), current_receiver(), N(str), (char *)keys[1], STRLEN(keys[1]), tmp, 64); - eosio_assert(res == STRLEN(vals[2]) && my_memcmp((void *)vals[2], (void *)tmp, res), "next carol"); + eosio_assert(uint32_t(res) == STRLEN(vals[2]) && my_memcmp((void *)vals[2], (void *)tmp, uint32_t(res)), "next carol"); res = next_str(current_receiver(), current_receiver(), N(str), (char *)keys[2], STRLEN(keys[2]), tmp, 64); - eosio_assert(res == STRLEN(vals[3]) && my_memcmp((void *)vals[3], (void *)tmp, res), "next dave"); + eosio_assert(uint32_t(res) == STRLEN(vals[3]) && my_memcmp((void *)vals[3], (void *)tmp, uint32_t(res)), "next dave"); res = lower_bound_str(current_receiver(), current_receiver(), N(str), (char *)keys[0], STRLEN(keys[0]), tmp, 64); - eosio_assert(res == STRLEN(vals[0]) && my_memcmp((void *)vals[0], (void *)tmp, res), "lowerbound alice"); + eosio_assert(uint32_t(res) == STRLEN(vals[0]) && my_memcmp((void *)vals[0], (void *)tmp, uint32_t(res)), "lowerbound alice"); res = upper_bound_str(current_receiver(), current_receiver(), N(str), (char *)keys[0], STRLEN(keys[0]), tmp, 64); - eosio_assert(res == STRLEN(vals[1]) && my_memcmp((void *)vals[1], (void *)tmp, res), "upperbound bob"); + eosio_assert(uint32_t(res) == STRLEN(vals[1]) && my_memcmp((void *)vals[1], (void *)tmp, uint32_t(res)), "upperbound bob"); res = lower_bound_str(current_receiver(), current_receiver(), N(str), (char *)keys[3], STRLEN(keys[3]), tmp, 64); - eosio_assert(res == STRLEN(vals[3]) && my_memcmp((void *)vals[3], (void *)tmp, res), "upperbound dave"); + eosio_assert(uint32_t(res) == STRLEN(vals[3]) && my_memcmp((void *)vals[3], (void *)tmp, uint32_t(res)), "upperbound dave"); res = upper_bound_str(current_receiver(), current_receiver(), N(str), (char *)keys[3], STRLEN(keys[3]), tmp, 64); eosio_assert(res == 0, "no upper_bound"); @@ -262,7 +262,7 @@ void test_db::key_str_general() { eosio_assert(res != 0, "store dave" ); res = load_str(current_receiver(), current_receiver(), N(str), (char*)keys[3], STRLEN(keys[3]), tmp, 64 ); - eosio_assert(res == STRLEN(vals[2]) && my_memcmp((void*)vals[2], (void*)tmp, res), "load updated carol" ); + eosio_assert(uint32_t(res) == STRLEN(vals[2]) && my_memcmp((void*)vals[2], (void*)tmp, uint32_t(res)), "load updated carol" ); } #if 0 @@ -1564,12 +1564,12 @@ void test_db::primary_i64_general() { int itr = db_find_i64(current_receiver(), current_receiver(), table1, N(bob)); eosio_assert(itr >= 0, ""); - int buffer_len = 5; + uint32_t buffer_len = 5; char value[50]; auto len = db_get_i64(itr, value, buffer_len); value[buffer_len] = '\0'; std::string s(value); - eosio_assert(len == strlen("bob's info"), "primary_i64_general - db_get_i64"); + eosio_assert(uint32_t(len) == strlen("bob's info"), "primary_i64_general - db_get_i64"); eosio_assert(s == "bob's", "primary_i64_general - db_get_i64"); buffer_len = 20; @@ -1584,10 +1584,10 @@ void test_db::primary_i64_general() int itr = db_find_i64(current_receiver(), current_receiver(), table1, N(bob)); eosio_assert(itr >= 0, ""); const char* new_value = "bob's new info"; - int new_value_len = strlen(new_value); + uint32_t new_value_len = strlen(new_value); db_update_i64(itr, current_receiver(), new_value, new_value_len); char ret_value[50]; - auto len = db_get_i64(itr, ret_value, new_value_len); + db_get_i64(itr, ret_value, new_value_len); ret_value[new_value_len] = '\0'; std::string sret(ret_value); eosio_assert(sret == "bob's new info", "primary_i64_general - db_update_i64"); @@ -1674,7 +1674,7 @@ void test_db::idx64_general() {110, N(joe)} }; - for (int i = 0; i < sizeof(records)/sizeof(records[0]); ++i) { + for (uint32_t i = 0; i < sizeof(records)/sizeof(records[0]); ++i) { db_idx64_store(current_receiver(), table, current_receiver(), records[i].ssn, &records[i].name); } @@ -1818,7 +1818,7 @@ void test_db::idx64_upperbound() { secondary_type ub_sec = N(alice); uint64_t ub_prim = 0; - const uint64_t alice_ssn = 265, allyson_ssn = 650; + const uint64_t allyson_ssn = 650; int ub = db_idx64_upperbound(current_receiver(), current_receiver(), table, &ub_sec, &ub_prim); eosio_assert(ub_prim == allyson_ssn && ub_sec == N(allyson), ""); eosio_assert(ub == db_idx64_find_primary(current_receiver(), current_receiver(), table, &ub_sec, allyson_ssn), err.c_str()); @@ -1834,7 +1834,6 @@ void test_db::idx64_upperbound() { secondary_type ub_sec = N(joe); uint64_t ub_prim = 0; - const uint64_t ssn = 110; int ub = db_idx64_upperbound(current_receiver(), current_receiver(), table, &ub_sec, &ub_prim); eosio_assert(ub_prim == 0 && ub_sec == N(joe), err.c_str()); eosio_assert(ub < 0, err.c_str()); diff --git a/contracts/test_api_mem/test_api_mem.cpp b/contracts/test_api_mem/test_api_mem.cpp index 4d511ef68..0d21950fa 100644 --- a/contracts/test_api_mem/test_api_mem.cpp +++ b/contracts/test_api_mem/test_api_mem.cpp @@ -14,7 +14,7 @@ extern "C" { } - void apply( unsigned long long code, unsigned long long action ) { + void apply( unsigned long long, unsigned long long action ) { //eosio::print("==> CONTRACT: ", code, " ", action, "\n"); diff --git a/contracts/test_api_mem/test_extended_memory.cpp b/contracts/test_api_mem/test_extended_memory.cpp index c3b0e54de..9650218bd 100644 --- a/contracts/test_api_mem/test_extended_memory.cpp +++ b/contracts/test_api_mem/test_extended_memory.cpp @@ -2,7 +2,7 @@ #include #include "../test_api/test_api.hpp" -using namespace eosio; +//using namespace eosio; void verify( const void* const ptr, const uint32_t val, const uint32_t size) { const char* char_ptr = (const char*)ptr; @@ -90,8 +90,8 @@ void test_extended_memory::test_page_memory_exceeded() { } void test_extended_memory::test_page_memory_negative_bytes() { - sbrk(-1); - eosio_assert(0, "Should have thrown exception for trying to remove memory"); + sbrk((uint32_t)-1); + eosio_assert(0, "Should have thrown exception for trying to remove memory"); } void test_extended_memory::test_initial_buffer() { diff --git a/contracts/test_api_mem/test_memory.cpp b/contracts/test_api_mem/test_memory.cpp index 694aa64c7..e3c1a12f0 100644 --- a/contracts/test_api_mem/test_memory.cpp +++ b/contracts/test_api_mem/test_memory.cpp @@ -2,10 +2,9 @@ * @file * @copyright defined in eos/LICENSE.txt */ -//#include + #include -using namespace eosio; void verify_mem(const void* const ptr, const uint32_t val, const uint32_t size) { -- GitLab