X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fbignum.h;h=4bda99d42515d31bb409df2dc89a446a2cc3063b;hb=05df71c9c292877e7469884227fd3ba84d02908b;hp=04e564bbfeef932116ad374f8114788625c5ab69;hpb=833d3bd6c578439105f9d69ef4a75dddf9b17280;p=novacoin.git diff --git a/src/bignum.h b/src/bignum.h index 04e564b..4bda99d 100644 --- a/src/bignum.h +++ b/src/bignum.h @@ -143,7 +143,7 @@ public: { uint64_t n = BN_get_word(this); if (!BN_is_negative(this)) - return (n > (uint64_t)std::numeric_limits::max() ? std::numeric_limits::max() : n); + return (n > (uint64_t)std::numeric_limits::max() ? std::numeric_limits::max() : (int32_t)n); else return (n > (uint64_t)std::numeric_limits::max() ? std::numeric_limits::min() : -(int32_t)n); } @@ -183,17 +183,17 @@ public: } *p++ = c; } - uint32_t nSize = p - (pch + 4); + uint32_t nSize = (uint32_t) (p - (pch + 4)); pch[0] = (nSize >> 24) & 0xff; pch[1] = (nSize >> 16) & 0xff; pch[2] = (nSize >> 8) & 0xff; pch[3] = (nSize) & 0xff; - BN_mpi2bn(pch, p - pch, this); + BN_mpi2bn(pch, (int)(p - pch), this); } uint64_t getuint64() { - unsigned int nSize = BN_bn2mpi(this, NULL); + size_t nSize = BN_bn2mpi(this, NULL); if (nSize < 4) return 0; std::vector vch(nSize); @@ -201,17 +201,20 @@ public: if (vch.size() > 4) vch[4] &= 0x7f; uint64_t n = 0; - for (unsigned int i = 0, j = vch.size()-1; i < sizeof(n) && j >= 4; i++, j--) + for (size_t i = 0, j = vch.size()-1; i < sizeof(n) && j >= 4; i++, j--) ((uint8_t*)&n)[i] = vch[j]; return n; } + //supress msvc C4127: conditional expression is constant + inline bool check(bool value) {return value;} + void setuint64(uint64_t n) { // Use BN_set_word if word size is sufficient for uint64_t - if (sizeof(n) <= sizeof(BN_ULONG)) + if (check(sizeof(n) <= sizeof(BN_ULONG))) { - if (!BN_set_word(this, n)) + if (!BN_set_word(this, (BN_ULONG)n)) throw bignum_error("CBigNum conversion from uint64_t : BN_set_word failed"); return; } @@ -233,12 +236,12 @@ public: } *p++ = c; } - uint32_t nSize = p - (pch + 4); + uint32_t nSize = (uint32_t) (p - (pch + 4)); pch[0] = (nSize >> 24) & 0xff; pch[1] = (nSize >> 16) & 0xff; pch[2] = (nSize >> 8) & 0xff; pch[3] = (nSize) & 0xff; - BN_mpi2bn(pch, p - pch, this); + BN_mpi2bn(pch, (int)(p - pch), this); } void setuint160(uint160 n) @@ -261,12 +264,12 @@ public: } *p++ = c; } - uint32_t nSize = p - (pch + 4); + uint32_t nSize = (uint32_t) (p - (pch + 4)); pch[0] = (nSize >> 24) & 0xff; pch[1] = (nSize >> 16) & 0xff; pch[2] = (nSize >> 8) & 0xff; pch[3] = (nSize >> 0) & 0xff; - BN_mpi2bn(pch, p - pch, this); + BN_mpi2bn(pch, (int) (p - pch), this); } uint160 getuint160() const @@ -279,7 +282,7 @@ public: if (vch.size() > 4) vch[4] &= 0x7f; uint160 n = 0; - for (unsigned int i = 0, j = vch.size()-1; i < sizeof(n) && j >= 4; i++, j--) + for (size_t i = 0, j = vch.size()-1; i < sizeof(n) && j >= 4; i++, j--) ((uint8_t*)&n)[i] = vch[j]; return n; } @@ -304,12 +307,12 @@ public: } *p++ = c; } - uint32_t nSize = p - (pch + 4); + uint32_t nSize = (uint32_t) (p - (pch + 4)); pch[0] = (nSize >> 24) & 0xff; pch[1] = (nSize >> 16) & 0xff; pch[2] = (nSize >> 8) & 0xff; pch[3] = (nSize >> 0) & 0xff; - BN_mpi2bn(pch, p - pch, this); + BN_mpi2bn(pch, (int) (p - pch), this); } uint256 getuint256() const @@ -322,14 +325,14 @@ public: if (vch.size() > 4) vch[4] &= 0x7f; uint256 n = 0; - for (unsigned int i = 0, j = vch.size()-1; i < sizeof(n) && j >= 4; i++, j--) + for (size_t i = 0, j = vch.size()-1; i < sizeof(n) && j >= 4; i++, j--) ((uint8_t*)&n)[i] = vch[j]; return n; } void setBytes(const std::vector& vchBytes) { - BN_bin2bn(&vchBytes[0], vchBytes.size(), this); + BN_bin2bn(&vchBytes[0], (int) vchBytes.size(), this); } std::vector getBytes() const @@ -349,7 +352,7 @@ public: void setvch(const std::vector& vch) { std::vector vch2(vch.size() + 4); - uint32_t nSize = vch.size(); + uint32_t nSize = (uint32_t) vch.size(); // BIGNUM's byte stream format expects 4 bytes of // big endian size data info at the front vch2[0] = (nSize >> 24) & 0xff; @@ -358,7 +361,7 @@ public: vch2[3] = (nSize >> 0) & 0xff; // swap data to big endian reverse_copy(vch.begin(), vch.end(), vch2.begin() + 4); - BN_mpi2bn(&vch2[0], vch2.size(), this); + BN_mpi2bn(&vch2[0], (int) vch2.size(), this); } std::vector getvch() const @@ -381,7 +384,7 @@ public: if (nSize >= 1) vch[4] = (nCompact >> 16) & 0xff; if (nSize >= 2) vch[5] = (nCompact >> 8) & 0xff; if (nSize >= 3) vch[6] = (nCompact >> 0) & 0xff; - BN_mpi2bn(&vch[0], vch.size(), this); + BN_mpi2bn(&vch[0], (int) vch.size(), this); return *this; } @@ -587,7 +590,7 @@ public: if(ret < 0){ throw bignum_error("CBigNum::isPrime :BN_is_prime"); } - return ret; + return ret != 0; } bool isOne() const {