X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fbignum.h;h=daf5f6883aa4e481586cff4bd3bf2f814b31f238;hb=8add7822cef7d39cb761f59e6b837159a4968982;hp=1a2406b935841dbc393d7f0ee9d7abd31b892d80;hpb=b2120e223a9a2282b26080cb126db9aad95b1282;p=novacoin.git diff --git a/src/bignum.h b/src/bignum.h index 1a2406b..daf5f68 100644 --- a/src/bignum.h +++ b/src/bignum.h @@ -1,5 +1,5 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2011 The Bitcoin developers +// Copyright (c) 2009-2012 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file license.txt or http://www.opensource.org/licenses/mit-license.php. #ifndef BITCOIN_BIGNUM_H @@ -11,6 +11,7 @@ #include "util.h" +/** Errors thrown by the bignum class */ class bignum_error : public std::runtime_error { public: @@ -18,7 +19,7 @@ public: }; - +/** RAII encapsulated BN_CTX (OpenSSL bignum context) */ class CAutoBN_CTX { protected: @@ -46,7 +47,7 @@ public: }; - +/** C++ wrapper for BIGNUM (OpenSSL bignum) */ class CBigNum : public BIGNUM { public: @@ -115,9 +116,9 @@ public: { unsigned long n = BN_get_word(this); if (!BN_is_negative(this)) - return (n > INT_MAX ? INT_MAX : n); + return (n > std::numeric_limits::max() ? std::numeric_limits::max() : n); else - return (n > INT_MAX ? INT_MIN : -(int)n); + return (n > std::numeric_limits::max() ? std::numeric_limits::min() : -(int)n); } void setint64(int64 n) @@ -243,7 +244,7 @@ public: std::vector getvch() const { unsigned int nSize = BN_bn2mpi(this, NULL); - if (nSize < 4) + if (nSize <= 4) return std::vector(); std::vector vch(nSize); BN_bn2mpi(this, &vch[0]); @@ -300,7 +301,7 @@ public: while (isxdigit(*psz)) { *this <<= 4; - int n = phexdigit[*psz++]; + int n = phexdigit[(unsigned char)*psz++]; *this += n; } if (fNegative) @@ -338,19 +339,19 @@ public: return ToString(16); } - unsigned int GetSerializeSize(int nType=0, int nVersion=VERSION) const + unsigned int GetSerializeSize(int nType=0, int nVersion=PROTOCOL_VERSION) const { return ::GetSerializeSize(getvch(), nType, nVersion); } template - void Serialize(Stream& s, int nType=0, int nVersion=VERSION) const + void Serialize(Stream& s, int nType=0, int nVersion=PROTOCOL_VERSION) const { ::Serialize(s, getvch(), nType, nVersion); } template - void Unserialize(Stream& s, int nType=0, int nVersion=VERSION) + void Unserialize(Stream& s, int nType=0, int nVersion=PROTOCOL_VERSION) { std::vector vch; ::Unserialize(s, vch, nType, nVersion);