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

Commit

Permalink
Merge pull request #5090 from EOSIO/fix/asset_mult_and_div
Browse files Browse the repository at this point in the history
Update asset.hpp
  • Loading branch information
b1bart authored Aug 7, 2018
2 parents 62420d2 + 8781da2 commit 48cea97
Showing 1 changed file with 6 additions and 4 deletions.
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

0 comments on commit 48cea97

Please sign in to comment.