From e94b3f60789705ea829f0faaeca26e1f31b3fed5 Mon Sep 17 00:00:00 2001 From: Jeeyong Um Date: Fri, 15 Feb 2019 20:37:41 +0900 Subject: [PATCH 1/2] Fix errors in eosio::asset::to_string() * fix double minus sign when the amount is negative * remove redundant decimal dot when fractional part doesn't exist --- libraries/eosiolib/asset.hpp | 8 +++++--- libraries/eosiolib/core/eosio/asset.hpp | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/libraries/eosiolib/asset.hpp b/libraries/eosiolib/asset.hpp index e0b36da253..0062250973 100644 --- a/libraries/eosiolib/asset.hpp +++ b/libraries/eosiolib/asset.hpp @@ -345,9 +345,11 @@ namespace eosio { change /= 10; } char str[p+32]; - const char* fmt = negative ? "-%lld.%s %s" : "%lld.%s %s"; - snprintf(str, sizeof(str), fmt, - (int64_t)(amount/p10), fraction, symbol.code().to_string().c_str()); + snprintf(str, sizeof(str), "%lld%s%s %s", + (int64_t)(amount/p10), + (fraction[0]) ? "." : "", + fraction, + symbol.code().to_string().c_str()); return {str}; } diff --git a/libraries/eosiolib/core/eosio/asset.hpp b/libraries/eosiolib/core/eosio/asset.hpp index 7b2b75f08a..e1509cabae 100644 --- a/libraries/eosiolib/core/eosio/asset.hpp +++ b/libraries/eosiolib/core/eosio/asset.hpp @@ -344,9 +344,11 @@ namespace eosio { change /= 10; } char str[p+32]; - const char* fmt = negative ? "-%lld.%s %s" : "%lld.%s %s"; - snprintf(str, sizeof(str), fmt, - (int64_t)(amount/p10), fraction, symbol.code().to_string().c_str()); + snprintf(str, sizeof(str), "%lld%s%s %s", + (int64_t)(amount/p10), + (fraction[0]) ? "." : "", + fraction, + symbol.code().to_string().c_str()); return {str}; } From 6fac70bdfce8480bdcd3daf1488a1d307f66fb67 Mon Sep 17 00:00:00 2001 From: Jeeyong Um Date: Sat, 16 Feb 2019 15:12:17 +0900 Subject: [PATCH 2/2] Remove unused boolean --- libraries/eosiolib/asset.hpp | 2 -- libraries/eosiolib/core/eosio/asset.hpp | 2 -- 2 files changed, 4 deletions(-) diff --git a/libraries/eosiolib/asset.hpp b/libraries/eosiolib/asset.hpp index 0062250973..9134db1ddb 100644 --- a/libraries/eosiolib/asset.hpp +++ b/libraries/eosiolib/asset.hpp @@ -322,7 +322,6 @@ namespace eosio { std::string to_string()const { int64_t p = (int64_t)symbol.precision(); int64_t p10 = 1; - bool negative = false; int64_t invert = 1; while( p > 0 ) { @@ -335,7 +334,6 @@ namespace eosio { if (amount < 0) { invert = -1; - negative = true; } auto change = (amount % p10) * invert; diff --git a/libraries/eosiolib/core/eosio/asset.hpp b/libraries/eosiolib/core/eosio/asset.hpp index e1509cabae..75c0914ba6 100644 --- a/libraries/eosiolib/core/eosio/asset.hpp +++ b/libraries/eosiolib/core/eosio/asset.hpp @@ -321,7 +321,6 @@ namespace eosio { std::string to_string()const { int64_t p = (int64_t)symbol.precision(); int64_t p10 = 1; - bool negative = false; int64_t invert = 1; while( p > 0 ) { @@ -334,7 +333,6 @@ namespace eosio { if (amount < 0) { invert = -1; - negative = true; } auto change = (amount % p10) * invert;