From 98bf1aafa45f1f29994aacce8009fae8c2003e7f Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Mon, 19 Feb 2018 16:41:32 -0500 Subject: [PATCH] fix warnings in many contracts --- CMakeModules/wasm.cmake | 2 +- contracts/eosio.system/eosio.system.hpp | 19 +- contracts/eosiolib/datastream.hpp | 2 +- contracts/eosiolib/db.h | 4 - contracts/eosiolib/db.hpp | 567 ------------------ contracts/eosiolib/eosiolib.cpp | 15 +- contracts/eosiolib/multi_index.hpp | 8 +- contracts/eosiolib/print.hpp | 2 +- contracts/eosiolib/privileged.h | 2 +- contracts/eosiolib/singleton.hpp | 2 +- contracts/eosiolib/table.hpp | 6 +- contracts/eosiolib/types.hpp | 2 +- contracts/eosiolib/varint.hpp | 2 +- .../multi_index_test/multi_index_test.cpp | 4 + contracts/stltest/stltest.cpp | 6 +- contracts/test.system/test.system.cpp | 18 +- 16 files changed, 47 insertions(+), 614 deletions(-) diff --git a/CMakeModules/wasm.cmake b/CMakeModules/wasm.cmake index 4887393f9..b762a54fa 100644 --- a/CMakeModules/wasm.cmake +++ b/CMakeModules/wasm.cmake @@ -111,7 +111,7 @@ macro(compile_wast) list(APPEND WASM_COMMAND -Wno-everything) else() list(APPEND WASM_COMMAND -Weverything -Wno-c++98-compat -Wno-old-style-cast -Wno-vla -Wno-vla-extension -Wno-c++98-compat-pedantic - -Wno-missing-prototypes -Wno-missing-variable-declarations -Wno-packed) + -Wno-missing-prototypes -Wno-missing-variable-declarations -Wno-packed -Wno-padded -Wno-c99-extensions) endif() foreach(folder ${ARG_INCLUDE_FOLDERS}) diff --git a/contracts/eosio.system/eosio.system.hpp b/contracts/eosio.system/eosio.system.hpp index 0fbe8c525..9080da094 100644 --- a/contracts/eosio.system/eosio.system.hpp +++ b/contracts/eosio.system/eosio.system.hpp @@ -34,12 +34,13 @@ namespace eosiosystem { struct producer_votes { account_name owner; + uint64_t padding = 0; uint128_t total_votes; uint64_t primary_key()const { return owner; } uint128_t by_votes()const { return total_votes; } - EOSLIB_SERIALIZE( producer_votes, (owner)(total_votes) ); + EOSLIB_SERIALIZE( producer_votes, (owner)(total_votes) ) }; typedef eosio::multi_index< N(producervote), producer_votes, indexed_by > @@ -54,7 +55,7 @@ namespace eosiosystem { uint64_t primary_key()const { return owner; } - EOSLIB_SERIALIZE( account_votes, (owner)(proxy)(last_update)(staked)(producers) ); + EOSLIB_SERIALIZE( account_votes, (owner)(proxy)(last_update)(staked)(producers) ) }; typedef eosio::multi_index< N(accountvotes), account_votes> account_votes_index_type; @@ -64,7 +65,7 @@ namespace eosiosystem { eosio::bytes packed_key; /// a packed public key object uint64_t primary_key()const { return owner; } - EOSLIB_SERIALIZE( producer_config, (owner)(packed_key) ); + EOSLIB_SERIALIZE( producer_config, (owner)(packed_key) ) }; typedef eosio::multi_index< N(producercfg), producer_config> producer_config_index_type; @@ -76,7 +77,7 @@ namespace eosiosystem { uint64_t primary_key()const { return owner; } - EOSLIB_SERIALIZE( total_resources, (owner)(total_net_weight)(total_cpu_weight)(total_ram) ); + EOSLIB_SERIALIZE( total_resources, (owner)(total_net_weight)(total_cpu_weight)(total_ram) ) }; @@ -102,7 +103,7 @@ namespace eosiosystem { EOSLIB_SERIALIZE( delegated_bandwidth, (from)(to)(net_weight)(cpu_weight) (start_pending_net_withdraw)(pending_net_withdraw)(deferred_net_withdraw_handler) - (start_pending_cpu_withdraw)(pending_cpu_withdraw)(deferred_cpu_withdraw_handler) ); + (start_pending_cpu_withdraw)(pending_cpu_withdraw)(deferred_cpu_withdraw_handler) ) }; @@ -120,13 +121,13 @@ namespace eosiosystem { account_name producer; bytes producer_key; - EOSLIB_SERIALIZE( regproducer, (producer)(producer_key) ); + EOSLIB_SERIALIZE( regproducer, (producer)(producer_key) ) }; ACTION( SystemAccount, regproxy ) { account_name proxy_to_register; - EOSLIB_SERIALIZE( regproxy, (proxy_to_register) ); + EOSLIB_SERIALIZE( regproxy, (proxy_to_register) ) }; ACTION( SystemAccount, delegatebw ) { @@ -151,7 +152,7 @@ namespace eosiosystem { ACTION( SystemAccount, nonce ) { eosio::string value; - EOSLIB_SERIALIZE( nonce, (value) ); + EOSLIB_SERIALIZE( nonce, (value) ) }; /// new id options: @@ -319,7 +320,7 @@ namespace eosiosystem { }); currency::inline_transfer( sv.voter, SystemAccount, sv.amount, "stake for voting" ); - }; + } ACTION( SystemAccount, voteproducer ) { account_name voter; diff --git a/contracts/eosiolib/datastream.hpp b/contracts/eosiolib/datastream.hpp index 284c3f8d6..67f708c0a 100644 --- a/contracts/eosiolib/datastream.hpp +++ b/contracts/eosiolib/datastream.hpp @@ -99,7 +99,7 @@ class datastream { * @brief Gets the position within the current stream * @return p the position within the current stream */ - inline size_t tellp()const { return _pos - _start; } + inline size_t tellp()const { return size_t(_pos - _start); } /** * Returns the number of remaining bytes that can be read/skipped diff --git a/contracts/eosiolib/db.h b/contracts/eosiolib/db.h index 5bf6ea18b..4d7957c30 100644 --- a/contracts/eosiolib/db.h +++ b/contracts/eosiolib/db.h @@ -304,8 +304,6 @@ int32_t update_str( account_name scope, table_name table, account_name bta, char * @param scope - the account scope that will be read, must exist in the transaction scopes list * @param code - identifies the code that controls write-access to the data * @param table - the ID/name of the table within the scope/code context to query - * @param key - location of the record key - * @param keylen - length of the record key * @param value - location to copy the front record value * @param valuelen - maximum length of the record value to read * @return the number of bytes read or -1 if key was not found @@ -316,8 +314,6 @@ int32_t update_str( account_name scope, table_name table, account_name bta, char * @param scope - the account scope that will be read, must exist in the transaction scopes list * @param code - identifies the code that controls write-access to the data * @param table - the ID/name of the table within the scope/code context to query - * @param key - location of the record key - * @param keylen - length of the record key * @param value - location to copy the back record value * @param valuelen - maximum length of the record value to read * @return the number of bytes read or -1 if key was not found diff --git a/contracts/eosiolib/db.hpp b/contracts/eosiolib/db.hpp index 558feded2..e4d0aa350 100644 --- a/contracts/eosiolib/db.hpp +++ b/contracts/eosiolib/db.hpp @@ -96,85 +96,6 @@ struct table_impl { } }; -/** - * @defgroup dualindextable Dual Index Table - * @brief Defines a type-safe C++ wrapper around the C Dual Index Table - * - * @tparam scope - the default account name/scope that this table is located within - * @tparam code - the code account name which has write permission to this table - * @tparam table - a unique identifier (name) for this table - * @tparam Record - the type of data stored in each row - * @tparam PrimaryType - the type of the first field stored in @ref Record - * @tparam SecondaryType - the type of the second field stored in @ref Record - * - * The primary and secondary indices are sorted as N-bit unsigned integers from lowest to highest. - * - * @code - * struct model { - * uint64_t primary; - * uint64_t secondary; - * uint64_t value; - * }; - * - * typedef table MyTable; - * model a { 1, 11, N(first) }; - * model b { 2, 22, N(second) }; - * model c { 3, 33, N(third) }; - * model d { 4, 44, N(fourth) }; - * - * bool res = MyTable::store(a); - * ASSERT(res, "store"); - * - * res = MyTable::store(b); - * ASSERT(res, "store"); - * - * res = MyTable::store(c); - * ASSERT(res, "store"); - * - * res = MyTable::store(d); - * ASSERT(res, "store"); - * - * model query; - * res = MyTable::primary_index::get(1, query); - * ASSERT(res && query.primary == 1 && query.value == N(first), "first"); - * - * res = MyTable::primary_index::front(query); - * ASSERT(res && query.primary == 4 && query.value == N(fourth), "front"); - * - * res = MyTable::primary_index::back(query); - * ASSERT(res && query.primary == 1 && query.value == N(first), "back"); - * - * res = MyTable::primary_index::previous(query); - * ASSERT(res && query.primary == 2 && query.value == N(second), "previous"); - * - * res = MyTable::primary_index::next(query); - * ASSERT(res && query.primary == 1 && query.value == N(first), "first"); - * - * res = MyTable::secondary_index::get(11, query); - * ASSERT(res && query.primary == 11 && query.value == N(first), "first"); - * - * res = MyTable::secondary_index::front(query); - * ASSERT(res && query.secondary == 44 && query.value == N(fourth), "front"); - * - * res = MyTable::secondary_index::back(query); - * ASSERT(res && query.secondary == 11 && query.value == N(first), "back"); - * - * res = MyTable::secondary_index::previous(query); - * ASSERT(res && query.secondary == 22 && query.value == N(second), "previous"); - * - * res = MyTable::secondary_index::next(query); - * ASSERT(res && query.secondary == 11 && query.value == N(first), "first"); - * - * res = MyTable::remove(query); - * ASSERT(res, "remove"); - * - * res = MyTable::get(query); - * ASSERT(!res, "not found already removed"); - * - * @endcode - * @ingroup databaseCpp - * @{ - */ template struct table { private: @@ -244,7 +165,6 @@ struct table { /** * @param p - reference to primary key to get the lower bound of; must be initialized with a value; * @param r - reference to a record to load the value to. - * @param s - account scope. default is current scope of the class * * @return true if successful read. */ @@ -255,7 +175,6 @@ struct table { /** * @param p - reference to primary key to get the upper bound of; must be initialized with a value; * @param r - reference to a record to load the value to. - * @param s - account scope. default is current scope of the class * * @return true if successful read. */ @@ -419,493 +338,7 @@ struct table { }; /// @} -template<> -struct table_impl { - - static int32_t front_primary( uint64_t code, uint64_t scope, uint64_t table_n, void* data, uint32_t len ) { - return front_i64( code, scope, table_n, data, len ); - } - - static int32_t back_primary( uint64_t code, uint64_t scope, uint64_t table_n, void* data, uint32_t len ) { - return back_i64( code, scope, table_n, data, len ); - } - - static int32_t load_primary( uint64_t code, uint64_t scope, uint64_t table_n, void* data, uint32_t len ) { - return load_i64( code, scope, table_n, data, len ); - } - - static int32_t next_primary( uint64_t code, uint64_t scope, uint64_t table_n, void* data, uint32_t len ) { - return next_i64( code, scope, table_n, data, len ); - } - - static int32_t previous_primary( uint64_t code, uint64_t scope, uint64_t table_n, void* data, uint32_t len ) { - return previous_i64( code, scope, table_n, data, len ); - } - - static int32_t lower_bound_primary( uint64_t code, uint64_t scope, uint64_t table_n, void* data, uint32_t len ) { - return lower_bound_i64( code, scope, table_n, data, len ); - } - - static int32_t upper_bound_primary( uint64_t code, uint64_t scope, uint64_t table_n, void* data, uint32_t len ) { - return upper_bound_i64( code, scope, table_n, data, len ); - } - - static int32_t remove( uint64_t scope, uint64_t table_n, const void* data ) { - return remove_i64( scope, table_n, (uint64_t*)data); - } - - static int32_t store( account_name scope, table_name table_n, account_name bta, const void* data, uint32_t len ) { - return store_i64( scope, table_n, bta, data, len ); - } - - static int32_t update( account_name scope, table_name table_n, account_name bta, const void* data, uint32_t len ) { - return update_i64( scope, table_n, bta, data, len ); - } -}; - - /** - * @defgroup singleindextable Single Index Table - * @brief Defines a type-safe C++ wrapper around the C Single Index Table - * - * @tparam scope - the default account name scope that this table is located within - * @tparam code - the code account name which has write permission to this table - * @tparam table - a unique identifier (name) for this table - * @tparam Record - the type of data stored in each row - * @tparam PrimaryType - the type of the first field stored in @ref Record - * - * Example - * @code - * - * struct my_model { - * uint128_t number; - * uint64_t name; - * }; - * - * typedef table MyTable; - * - * my_model a { 1, N(one) }; - * my_model b { 2, N(two) }; - * my_model c { 3, N(three) }; - * my_model d { 4, N(four) }; - * - * bool res = MyTable::store(a); - * ASSERT(res, "store"); - - * res = MyTable::store(b); - * ASSERT(res, "store"); - * - * res = MyTable::store(c); - * ASSERT(res, "store"); - * - * res = MyTable::store(d); - * ASSERT(res, "store"); - * - * my_model query; - * res = MyTable::front(query); - * ASSERT(res && query.number == 4 && query.name == N(four), "front"); - * - * res = MyTable::back(query); - * ASSERT(res && query.number == 1 && query.name == N(one), "back"); - * - * res = MyTable::primary_index::previous(query); - * ASSERT(res && query.number == 2 && query.name == N(two), "previous"); - * - * res = MyTable::primary_index::next(query); - * ASSERT(res && query.number == 1 && query.name == N(one), "next"); - * - * query.number = 4; - * res = MyTable::get(query); - * ASSERT(res && query.number == 4 && query.name = N(four), "get"); - * - * query.name = N(Four); - * res = MyTable.update(query); - * ASSERT(res && query.number == 4 && query.name == N(Four), "update"); - * - * res = MyTable.remove(query); - * ASSERT(res, "remove"); - * - * res = MyTable.get(query); - * ASSERT(!res, "get of removed record"); - * - * @endcode - * @ingroup databaseCpp - * @{ - */ -template -struct table { - private: - typedef table_impl impl; - static_assert( sizeof(PrimaryType) <= sizeof(Record), "invalid template parameters" ); - - public: - typedef PrimaryType primary; - /** - * @brief Primary Index of the Table - */ - struct primary_index { - /** - * @param r - reference to a record to store the front. - * @param s - scope; defaults to scope of the class. - * - * @return true if successfully retrieved the front of the table. - */ - static bool front( Record& r, uint64_t s = scope ) { - return impl::front_primary( code, s, table_n, &r, sizeof(Record) ) == sizeof(Record); - } - - /** - * @param r - reference to a record to store the back. - * @param s - scope; defaults to scope of the class. - * - * @return true if successfully retrieved the back of the table. - */ - static bool back( Record& r, uint64_t s = scope ) { - return impl::back_primary( code, s, table_n, &r, sizeof(Record) ) == sizeof(Record); - } - - /** - * @param r - reference to store the next record. Must be initialized with a key. - * @param s - scope; defaults to scope of the class. - * - * @return true if successfully retrieved the next record. - */ - static bool next( Record& r, uint64_t s = scope ) { - return impl::next_primary( code, s, table_n, &r, sizeof(Record) ) == sizeof(Record); - } - - /** - * @param r - reference to store previous record. Must be initialized with a key. - * @param s - scope; defaults to scope of the class. - * - * @return true if successfully retrieved the previous record. - */ - static bool previous( Record& r, uint64_t s = scope ) { - return impl::previous_primary( code, s, table_n, &r, sizeof(Record) ) == sizeof(Record); - } - - /** - * @param p - reference to the primary key to retrieve the record. - * @param r - reference to hold the result of the query. - * @param s - scope; defaults to scope of the class. - * @return true if successfully retrieved the record. - */ - static bool get( const PrimaryType& p, Record& r, uint64_t s = scope ) { - *reinterpret_cast(&r) = p; - return impl::load_primary( code, s, table_n, &r, sizeof(Record) ) == sizeof(Record); - } - - /** - * @param p - reference to the primary key to retrieve the lower bound. - * @param r - reference to hold the result of the query. - * @param s - scope; defaults to scope of the class. - * @return true if successfully retrieved the record. - */ - static bool lower_bound( const PrimaryType& p, Record& r, uint64_t s = scope ) { - *reinterpret_cast(&r) = p; - return impl::lower_bound_primary( code, s, table_n, &r, sizeof(Record) ) == sizeof(Record); - } - - /** - * @param p - reference to the primary key to retrieve the upper bound. - * @param r - reference to hold the result of the query. - * @param s - scope; defaults to scope of the class. - * @return true if successfully retrieved the record. - */ - static bool upper_bound( const PrimaryType& p, Record& r, uint64_t s = scope ) { - *reinterpret_cast(&r) = p; - return impl::upper_bound_primary( code, s, table_n, &r, sizeof(Record) ) == sizeof(Record); - } - - /** - * @param r - reference to record to be removed. - * @param s - scope; defaults to scope of the class. - * @return true if successfully removed. - */ - static bool remove( const Record& r, uint64_t s = scope ) { - return impl::remove( s, table_n, &r ) != 0; - } - }; - - - /** - * @brief Fetches the front of the table - * @details Fetches the front of the table - * @param r - reference to hold the value - * @param s - scope; defaults to scope of the class. - * @return true if successfully retrieved the front - */ - static bool front( Record& r, uint64_t s = scope ) { return primary_index::front(r, s); } - - /** - * @brief Fetches the back of the table - * @details Fetches the back of the table - * @param r - reference to hold the value - * @param s - scope; defaults to scope of the class. - * @return true if successfully retrieved the back - */ - static bool back( Record& r, uint64_t s = scope ) { return primary_index::back(r, s); } - - /** - * @brief Retrieves the record for the specified primary key - * @details Retrieves the record for the specified primary key - * @param p - the primary key of the record to fetch - * @param r - reference of record to hold return value - * @param s - scope; defaults to scope of the class. - * @return true if get succeeds. - */ - static bool get( const PrimaryType& p, Record& r, uint64_t s = scope ) { - *reinterpret_cast(&r) = p; - return impl::load_primary( code, s, table_n, &r, sizeof(Record) ) == sizeof(Record); - } - - /** - * @brief Retrieves a record based on initialized primary key value - * @details Retrieves a record based on initialized primary key value - * @param r - reference of a record to hold return value; must be initialized to the primary key to be fetched. - * @param s - scope; defaults to scope of the class. - * @return true if get succeeds. - */ - static bool get( Record& r, uint64_t s = scope ) { - return impl::load_primary( code, s, table_n, &r, sizeof(Record) ) == sizeof(Record); - } - - /** - * @brief Store a record to the table - * @details Store a record to the table - * @param r - the record to be stored. - * @param s - scope; defaults to scope of the class. - * @return true if store succeeds. - */ - static bool store( const Record& r, uint64_t s = scope, uint64_t b = bta ) { - return impl::store( s, table_n, b, &r, sizeof(r) ) != 0; - } - - /** - * @brief Update a record in the table. - * @details Update a record in the table. - * @param r - the record to be updated including the updated values (cannot update the index). - * @param s - scope; defaults to scope of the class. - * @return true if update succeeds. - */ - static bool update( const Record& r, uint64_t s = scope, uint64_t b = bta ) { - return impl::update( s, table_n, b, &r, sizeof(r) ) != 0; - } - - /** - * @brief Remove a record from the table. - * @details Remove a record from the table. - * @param r - the record to be removed. - * @param s - scope; defaults to scope of the class. - * @return true if remove succeeds. - */ - static bool remove( const Record& r, uint64_t s = scope ) { - return impl::remove( s, table_n, &r ) != 0; - } -}; /// @} singleindextable - - -template<> -struct table_impl_obj { - - static int32_t store( account_name scope, table_name table_n, account_name bta, char* key, uint32_t keylen, char* data, uint32_t datalen ) { - return store_str( scope, table_n, bta, key, keylen, data, datalen ); - } - - static int32_t update( account_name scope, table_name table_n, account_name bta, char* key, uint32_t keylen, char* data, uint32_t datalen ) { - return update_str( scope, table_n, bta, key, keylen, data, datalen ); - } - - static int32_t front( account_name code, account_name scope, table_name table_n, char* data, uint32_t len ) { - return front_str( code, scope, table_n, data, len ); - } - - static int32_t back( account_name code, account_name scope, table_name table_n, char* data, uint32_t len ) { - return back_str( code, scope, table_n, data, len ); - } - - static int32_t load( account_name code, account_name scope, table_name table_n, char* key, uint32_t keylen, char* data, uint32_t datalen ) { - return load_str( code, scope, table_n, key, keylen, data, datalen ); - } - - static int32_t next( account_name code, account_name scope, table_name table_n, char* key, uint32_t keylen, char* data, uint32_t datalen ) { - return next_str( code, scope, table_n, key, keylen, data, datalen ); - } - - static int32_t previous( account_name code, account_name scope, table_name table_n, char* key, uint32_t keylen, char* data, uint32_t datalen ) { - return previous_str( code, scope, table_n, key, keylen, data, datalen ); - } - - static int32_t lower_bound( account_name code, account_name scope, table_name table_n, char* key, uint32_t keylen, char* data, uint32_t datalen ) { - return lower_bound_str( code, scope, table_n, key, keylen, data, datalen ); - } - - static int32_t upper_bound( account_name code, account_name scope, table_name table_n, char* key, uint32_t keylen, char* data, uint32_t datalen ) { - return upper_bound_str( code, scope, table_n, key, keylen, data, datalen ); - } - - static int32_t remove( account_name scope, table_name table_n, char* key, uint32_t keylen ) { - return remove_str( scope, table_n, key, keylen ); - } -}; - -/** - * @defgroup singlevarindextable Single Variable Length Index Table - * @brief Defines a type-safe C++ wrapper around the C Single Variable Length Index Table (e.g. string index) - * - * @tparam scope - the default account name scope that this table is located within - * @tparam code - the code account name which has write permission to this table - * @tparam table_n - a unique identifier (name) for this table - * @tparam PrimaryType - the type of the first field stored in @ref Record - * - * @ingroup databaseCpp - * @{ - */ - -template -struct var_table { - private: - typedef table_impl_obj impl; - - public: - typedef PrimaryType primary; - - /** - * @brief Store a record to the table - * @details Store a record to the table - * @param key - key of the data to be stored - * @param keylen - length of the key - * @param record - data to be stored - * @param len - length of data to be stored - * @return 1 if a new record was created, 0 if an existing record was updated - */ - int32_t store( primary key, uint32_t keylen, char* record, uint32_t len ) { - return impl::store( scope, table_n, bta, key, keylen, record, len ); - } - - /** - * @brief Update a record in the table - * @details Update a record to the table - * @param key - key of the data to be updated - * @param keylen - length of the key - * @param record - data to be updated - * @param len - length of data to be updated - * @return 1 if the record was updated, 0 if no record with key was found - */ - int32_t update( primary key, uint32_t keylen, char* record, uint32_t len ) { - return impl::update( scope, table_n, bta, key, keylen, record, len ); - } - - /** - * @brief Fetches the front of the table - * @details Fetches the front of the table - * @param key - key of the data to be updated - * @param keylen - length of the key - * @param record - data to be updated - * @param len - length of data to be updated - * @return the number of bytes read or -1 if key was not found - */ - int32_t front( char* record, uint32_t len ) { - return impl::front( code, scope, table_n, record, len ); - } - - /** - * @brief Fetches the back of the table - * @details Fetches the back of the table - * @param key - key of the data to be updated - * @param keylen - length of the key - * @param record - data to be updated - * @param len - length of data to be updated - * @return the number of bytes read or -1 if key was not found - */ - int32_t back( char* record, uint32_t len ) { - return impl::back( code, scope, table_n, record, len ); - } - - /** - * @brief Fetches a record from the table - * @details Fetches a record from the table - * @param key - key of the data to be updated - * @param keylen - length of the key - * @param record - data to be updated - * @param len - length of data to be updated - * @return the number of bytes read or -1 if key was not found - */ - int32_t load( primary key, uint32_t keylen, char* record, uint32_t len ) { - return impl::load( code, scope, table_n, key, keylen, record, len ); - } - - /** - * @brief Fetches a record which key is next of the given key - * @details Fetches a record which key is next of the given key - * @param key - key of the data to be updated - * @param keylen - length of the key - * @param record - data to be updated - * @param len - length of data to be updated - * @return the number of bytes read or -1 if key was not found - */ - int32_t next( primary key, uint32_t keylen, char* record, uint32_t len ) { - return impl::next( code, scope, table_n, key, keylen, record, len ); - } - - /** - * @brief Fetches a record which key is previous of the given key - * @details Fetches a record which key is previous of the given key - * @param key - key of the data to be updated - * @param keylen - length of the key - * @param record - data to be updated - * @param len - length of data to be updated - * @return the number of bytes read or -1 if key was not found - */ - int32_t previous( primary key, uint32_t keylen, char* record, uint32_t len ) { - return impl::previous( code, scope, table_n, key, keylen, record, len ); - } - - /** - * @brief Fetches a record which key is the nearest larger than or equal to the given key - * @details Fetches a record which key is the nearest larger than or equal to the given key - * @param key - key of the data to be updated - * @param keylen - length of the key - * @param record - data to be updated - * @param len - length of data to be updated - * @return the number of bytes read or -1 if key was not found - */ - int32_t lower_bound( primary key, uint32_t keylen, char* record, uint32_t len ) { - return impl::lower_bound( code, scope, table_n, key, keylen, record, len ); - } - - /** - * @brief Fetches a record which key is the nearest larger than the given key - * @details Fetches a record which key is the nearest larger than the given key - * @param key - key of the data to be updated - * @param keylen - length of the key - * @param record - data to be updated - * @param len - length of data to be updated - * @return the number of bytes read or -1 if key was not found - */ - int32_t upper_bound( primary key, uint32_t keylen, char* record, uint32_t len ) { - return impl::upper_bound( code, scope, table_n, key, keylen, record, len ); - } - - /** - * @brief Remove a record from the table. - * @details Remove a record from the table. - * @param key - key of the data to be updated - * @param keylen - length of the key - * @param record - data to be updated - * @param len - length of data to be updated - * @return 1 if a record was removed, and 0 if no record with key was found - */ - int32_t remove( primary key, uint32_t keylen ) { - return impl::remove( scope, table_n, key, keylen ); - } -}; - -/// @} singlevarindextable } // namespace eosio -#define TABLE2(NAME, CODE, SCOPE, TABLE, TYPE, PRIMARY_NAME, PRIMARY_TYPE, SECONDARY_NAME, SECONDARY_TYPE) \ - using NAME = eosio::table; \ - typedef NAME::primary_index PRIMARY_NAME; \ - typedef NAME::secondary_index SECONDARY_NAME; diff --git a/contracts/eosiolib/eosiolib.cpp b/contracts/eosiolib/eosiolib.cpp index cb4805ac3..d72f79e30 100644 --- a/contracts/eosiolib/eosiolib.cpp +++ b/contracts/eosiolib/eosiolib.cpp @@ -47,7 +47,7 @@ namespace eosio { return nullptr; } - const uint32_t new_heap_size = remaining > _new_heap_size ? _new_heap_size : remaining; + const uint32_t new_heap_size = uint32_t(remaining) > _new_heap_size ? _new_heap_size : uint32_t(remaining); char* new_memory_start = static_cast(sbrk(new_heap_size)); // if we can expand the current memory, keep working with it if (current_memory->expand_memory(new_memory_start, new_heap_size)) @@ -281,12 +281,11 @@ namespace eosio { return nullptr; } - const int32_t diff = size - *orig_ptr_size; - if (diff < 0) + if( *orig_ptr_size > size ) { // use a buffer_ptr to allocate the memory to free char* const new_ptr = ptr + size + _size_marker; - buffer_ptr excess_to_free(new_ptr, -diff, _heap + _heap_size); + buffer_ptr excess_to_free(new_ptr, *orig_ptr_size - size, _heap + _heap_size); excess_to_free.mark_free(); return ptr; @@ -295,11 +294,11 @@ namespace eosio { else if (orig_buffer_end == &_heap[_offset]) { orig_buffer.size(size); - _offset += diff; + _offset += size - *orig_ptr_size; return ptr; } - if (-diff == 0) + if (size == *orig_ptr_size ) return ptr; if (!orig_buffer.merge_contiguous_if_available(size)) @@ -416,7 +415,7 @@ namespace eosio { bool merge_contiguous(uint32_t needed_size, bool all_or_nothing) { // do not bother if there isn't contiguious space to allocate - if (all_or_nothing && _heap_end - _ptr < needed_size) + if( all_or_nothing && uint32_t(_heap_end - _ptr) < needed_size ) return false; uint32_t possible_size = _size; @@ -470,7 +469,7 @@ namespace eosio { uint32_t _heaps_actual_size; uint32_t _active_heap; uint32_t _active_free_heap; - static const uint32_t _alloc_memory_mask = 1 << 31; + static const uint32_t _alloc_memory_mask = uint32_t(1) << 31; }; memory_manager memory_heap; diff --git a/contracts/eosiolib/multi_index.hpp b/contracts/eosiolib/multi_index.hpp index 2c76f3a2d..3b06278f0 100644 --- a/contracts/eosiolib/multi_index.hpp +++ b/contracts/eosiolib/multi_index.hpp @@ -168,7 +168,7 @@ class multi_index const multi_index& __idx; int __primary_itr; - int __iters[sizeof...(Indicies)]; + int __iters[sizeof...(Indicies)+(sizeof...(Indicies)==0)]; }; uint64_t _code; @@ -214,10 +214,11 @@ class multi_index return *cacheitr; auto size = db_get_i64( itr, nullptr, 0 ); + eosio_assert( size >= 0, "error reading iterator" ); char tmp[size]; - db_get_i64( itr, tmp, size ); + db_get_i64( itr, tmp, uint32_t(size) ); - datastream ds(tmp,size); + datastream ds(tmp,uint32_t(size)); auto result = _items_index.emplace( *this, [&]( auto& i ) { T& val = static_cast(i); @@ -239,7 +240,6 @@ class multi_index public: multi_index( uint64_t code, uint64_t scope ):_code(code),_scope(scope){} - ~multi_index() { } uint64_t get_code()const { return _code; } uint64_t get_scope()const { return _scope; } diff --git a/contracts/eosiolib/print.hpp b/contracts/eosiolib/print.hpp index 236a05f8b..5e94df192 100644 --- a/contracts/eosiolib/print.hpp +++ b/contracts/eosiolib/print.hpp @@ -44,7 +44,7 @@ namespace eosio { * @param num to be printed */ inline void print( int num ) { - printi(num); + printi(uint64_t(num)); } /** diff --git a/contracts/eosiolib/privileged.h b/contracts/eosiolib/privileged.h index 990da41c8..67359b54a 100644 --- a/contracts/eosiolib/privileged.h +++ b/contracts/eosiolib/privileged.h @@ -16,7 +16,7 @@ extern "C" { * @{ */ - void set_resource_limits( account_name account, int64_t ram_bytes, int64_t net_weight, int64_t cpu_weight, int64_t ignored); + void set_resource_limits( account_name account, uint64_t ram_bytes, uint64_t net_weight, uint64_t cpu_weight, int64_t ignored); void set_active_producers( char *producer_data, size_t producer_data_size ); diff --git a/contracts/eosiolib/singleton.hpp b/contracts/eosiolib/singleton.hpp index 6f3f86236..962b4a44f 100644 --- a/contracts/eosiolib/singleton.hpp +++ b/contracts/eosiolib/singleton.hpp @@ -38,7 +38,7 @@ namespace eosio { if ( read < 0 ) { return def; } - return unpack( temp + sizeof(SingletonName), read ); + return unpack( temp + sizeof(SingletonName), size_t(read) ); } static T get_or_create( scope_name scope = Code, const T& def = T() ) { diff --git a/contracts/eosiolib/table.hpp b/contracts/eosiolib/table.hpp index 2b641f2a4..7f5f388e0 100644 --- a/contracts/eosiolib/table.hpp +++ b/contracts/eosiolib/table.hpp @@ -23,7 +23,7 @@ namespace eosio { auto read = load_i64( DefaultScope, scope , TableName, temp, sizeof(temp) ); eosio_assert( read > 0, "key does not exist" ); - datastream ds(temp, read); + datastream ds(temp, uint32_t(read) ); T result; ds >> result; return result; @@ -39,7 +39,7 @@ namespace eosio { return def; } - datastream ds(temp, read); + datastream ds(temp, uint32_t(read) ); T result; ds >> result; return result; @@ -54,7 +54,7 @@ namespace eosio { return def; } - datastream ds(temp, read); + datastream ds(temp, uint32_t(read) ); T result; ds >> result; return result; diff --git a/contracts/eosiolib/types.hpp b/contracts/eosiolib/types.hpp index e4ab9f1f2..2d182ef73 100644 --- a/contracts/eosiolib/types.hpp +++ b/contracts/eosiolib/types.hpp @@ -39,7 +39,7 @@ namespace eosio { for( uint32_t i = 0; i <= 12; ++i ) { uint64_t c = 0; - if( i < len && i <= 12 ) c = char_to_symbol( str[i] ); + if( i < len && i <= 12 ) c = uint64_t(char_to_symbol( str[i] )); if( i < 12 ) { c &= 0x1f; diff --git a/contracts/eosiolib/varint.hpp b/contracts/eosiolib/varint.hpp index 3fd084b5a..ac8fe3ce7 100644 --- a/contracts/eosiolib/varint.hpp +++ b/contracts/eosiolib/varint.hpp @@ -102,7 +102,7 @@ struct signed_int { template friend DataStream& operator << ( DataStream& ds, const signed_int& v ){ - uint32_t val = (v.value<<1) ^ (v.value>>31); + uint32_t val = uint32_t((v.value<<1) ^ (v.value>>31)); do { uint8_t b = uint8_t(val) & 0x7f; val >>= 7; diff --git a/contracts/multi_index_test/multi_index_test.cpp b/contracts/multi_index_test/multi_index_test.cpp index 247d0cc8a..e00874105 100644 --- a/contracts/multi_index_test/multi_index_test.cpp +++ b/contracts/multi_index_test/multi_index_test.cpp @@ -5,6 +5,7 @@ using namespace eosio; struct limit_order { uint64_t id; + uint64_t padding = 0; uint128_t price; uint64_t expiration; account_name owner; @@ -32,6 +33,7 @@ extern "C" { }); orders.update( order, payer, [&]( auto& o ) { + o.expiration = 4; }); const auto* o = orders.find( 1 ); @@ -41,9 +43,11 @@ extern "C" { auto expidx = orders.get_index(); for( const auto& item : orders ) { + (void)item.id; } for( const auto& item : expidx ) { + (void)item.id; } auto lower = expidx.lower_bound(4); diff --git a/contracts/stltest/stltest.cpp b/contracts/stltest/stltest.cpp index 1cd4fe317..457819ef3 100644 --- a/contracts/stltest/stltest.cpp +++ b/contracts/stltest/stltest.cpp @@ -193,7 +193,7 @@ namespace stltest { prints("f() called\n"); } - static void on(const message& msg) { + static void on( const message& ) { /* manual initialization of global variable new(&std::__start_std_streams)std::ios_base::Init; */ @@ -244,7 +244,7 @@ namespace stltest { std::map m; m.emplace(0, 1); - auto mit = m.lower_bound(2); + m.lower_bound(2); std::set st; st.insert(0); @@ -257,7 +257,7 @@ namespace stltest { //hs.insert(0); sort(dq.begin(), dq.end()); - auto lit = find_if(l.begin(), l.end(), [](uint32_t f) { return f < 10; }); + find_if(l.begin(), l.end(), [](uint32_t f) { return f < 10; }); prints("STL test done.\n"); //std::cout << "STL test done." << std::endl; } diff --git a/contracts/test.system/test.system.cpp b/contracts/test.system/test.system.cpp index 488f1919c..88062532a 100644 --- a/contracts/test.system/test.system.cpp +++ b/contracts/test.system/test.system.cpp @@ -18,33 +18,33 @@ namespace testsystem { }; struct set_account_limits : dispatchable { - account_name account; - int64_t ram_bytes; - int64_t net_weight; - int64_t cpu_weight; + account_name account; + uint64_t ram_bytes = 0; + uint64_t net_weight = 0; + uint64_t cpu_weight = 0; static void process(const set_account_limits& act) { set_resource_limits(act.account, act.ram_bytes, act.net_weight, act.cpu_weight, 0); } - EOSLIB_SERIALIZE( set_account_limits, (account)(ram_bytes)(net_weight)(cpu_weight) ); + EOSLIB_SERIALIZE( set_account_limits, (account)(ram_bytes)(net_weight)(cpu_weight) ) }; struct set_global_limits : dispatchable { int64_t cpu_usec_per_period; - static void process(const set_global_limits& act) { + static void process(const set_global_limits& ) { // TODO: support this } - EOSLIB_SERIALIZE( set_global_limits, (cpu_usec_per_period) ); + EOSLIB_SERIALIZE( set_global_limits, (cpu_usec_per_period) ) }; struct producer_key { account_name account; std::string public_key; - EOSLIB_SERIALIZE( producer_key, (account)(public_key) ); + EOSLIB_SERIALIZE( producer_key, (account)(public_key) ) }; struct set_producers : dispatchable { @@ -57,7 +57,7 @@ namespace testsystem { set_active_producers(buffer, sizeof(buffer)); } - EOSLIB_SERIALIZE( set_producers, (version)(producers) ); + EOSLIB_SERIALIZE( set_producers, (version)(producers) ) }; struct require_auth : dispatchable { -- GitLab