Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Update asset.hpp #5090

Merged
merged 3 commits into from
Aug 7, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions contracts/eosiolib/asset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ namespace eosio {
* @post The amount of this asset is multiplied by a
*/
asset& operator*=( int64_t a ) {
eosio_assert( a == 0 || (amount * a) / a == amount, "multiplication overflow or underflow" );
amount *= a;
eosio_assert( -max_amount <= amount, "multiplication underflow" );
eosio_assert( amount <= max_amount, "multiplication overflow" );
int128_t tmp = (int128_t)amount * (int128_t)a;
eosio_assert( tmp <= max_amount, "multiplication overflow" );
eosio_assert( tmp >= -max_amount, "multiplication underflow" );
amount = (int64_t)tmp;
return *this;
}

Expand Down Expand Up @@ -218,6 +218,8 @@ namespace eosio {
* @post The amount of this asset is divided by a
*/
asset& operator/=( int64_t a ) {
eosio_assert( a != 0, "divide by zero" );
eosio_assert( !(amount == std::numeric_limits<int64_t>::min() && a == -1), "signed division overflow" );
amount /= a;
return *this;
}
Expand Down