diff --git a/src/ripple/types/api/UInt128.h b/src/ripple/types/api/UInt128.h index 84aac2290..569fc3f7b 100644 --- a/src/ripple/types/api/UInt128.h +++ b/src/ripple/types/api/UInt128.h @@ -31,6 +31,12 @@ namespace ripple { class uint128 : public base_uint128 { +private: + uint128 (value_type const* ptr) + { + memcpy (pn, ptr, bytes); + } + public: typedef base_uint128 basetype; @@ -52,15 +58,6 @@ public: return *this; } - // VFALCO NOTE This looks dangerous and wouldn't be obvious at call - // sites what is being performed here. - // - explicit uint128 (const base_uint256& b) - { - for (int i = 0; i < WIDTH; i++) - pn[i] = b.pn[i]; - } - explicit uint128 (Blob const& vch) { if (vch.size () == size ()) @@ -69,6 +66,10 @@ public: zero (); } + static uint128 low128(base_uint256 const& b) + { + return uint128 (b.data()); + } }; } diff --git a/src/ripple/types/api/UInt160.h b/src/ripple/types/api/UInt160.h index 2fdcd6d19..12f411c56 100644 --- a/src/ripple/types/api/UInt160.h +++ b/src/ripple/types/api/UInt160.h @@ -53,7 +53,7 @@ public: return *this; } - uint160 (std::uint64_t b) + explicit uint160 (std::uint64_t b) { *this = b; } diff --git a/src/ripple/types/api/UInt256.h b/src/ripple/types/api/UInt256.h index 3e725b351..d84bf476a 100644 --- a/src/ripple/types/api/UInt256.h +++ b/src/ripple/types/api/UInt256.h @@ -56,7 +56,7 @@ public: return *this; } - uint256 (std::uint64_t b) + explicit uint256 (std::uint64_t b) { *this = b; } diff --git a/src/ripple/types/api/base_uint.h b/src/ripple/types/api/base_uint.h index 8a39301a5..7413e71cb 100644 --- a/src/ripple/types/api/base_uint.h +++ b/src/ripple/types/api/base_uint.h @@ -50,6 +50,9 @@ inline int Testuint256AdHoc (std::vector vArg); template class base_uint { + static_assert ((BITS % 32) == 0, + "The length of a base_uint must be a multiple of 32."); + protected: enum { WIDTH = BITS / 32 }; @@ -129,9 +132,6 @@ protected: */ base_uint (void const* data, FromVoid) { - // BITS must be a multiple of 32 - static_bassert ((BITS % 32) == 0); - memcpy (&pn [0], data, BITS / 8); } public: diff --git a/src/ripple_app/contracts/ScriptData.h b/src/ripple_app/contracts/ScriptData.h index 9f87f973d..703afe361 100644 --- a/src/ripple_app/contracts/ScriptData.h +++ b/src/ripple_app/contracts/ScriptData.h @@ -70,7 +70,7 @@ public: } virtual uint160 getUint160 () { - return (0); + return uint160(0); } //virtual bool isCurrency(){ return(false); } diff --git a/src/ripple_data/crypto/CKeyDeterministic.cpp b/src/ripple_data/crypto/CKeyDeterministic.cpp index 0253b8815..ce00c97fe 100644 --- a/src/ripple_data/crypto/CKeyDeterministic.cpp +++ b/src/ripple_data/crypto/CKeyDeterministic.cpp @@ -30,7 +30,7 @@ uint128 CKey::PassPhraseToKey (const std::string& passPhrase) s.addRaw (passPhrase); uint256 hash256 = s.getSHA512Half (); - uint128 ret (hash256); + uint128 ret (uint128::low128(hash256)); s.secureErase (); diff --git a/src/ripple_data/protocol/STAmount.cpp b/src/ripple_data/protocol/STAmount.cpp index 82936bf67..87addd121 100644 --- a/src/ripple_data/protocol/STAmount.cpp +++ b/src/ripple_data/protocol/STAmount.cpp @@ -765,19 +765,23 @@ STAmount& STAmount::operator= (std::uint64_t v) STAmount& STAmount::operator+= (std::uint64_t v) { - if (mIsNative) - setSNValue (getSNValue () + static_cast (v)); - else *this += STAmount (mCurrency, v); + assert (mIsNative); + if (!mIsNative) + throw std::runtime_error ("not native"); + + setSNValue (getSNValue () + static_cast (v)); return *this; } STAmount& STAmount::operator-= (std::uint64_t v) { - if (mIsNative) - setSNValue (getSNValue () - static_cast (v)); - else *this -= STAmount (mCurrency, v); + assert (mIsNative); + if (!mIsNative) + throw std::runtime_error ("not native"); + + setSNValue (getSNValue () - static_cast (v)); return *this; }