X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fbignum.h;h=3730b47da95a376f47c114cc9eaaf6c4a103cc0b;hb=ef17ac0211ddd486127e1f94756fbb3fd704a9b4;hp=f37d7edd8b65be732478afa2f74a2b49334d0bf5;hpb=59b5e172f9fed2d27202168630550e21ef995105;p=novacoin.git diff --git a/src/bignum.h b/src/bignum.h index f37d7ed..3730b47 100644 --- a/src/bignum.h +++ b/src/bignum.h @@ -59,22 +59,34 @@ public: CBigNum(const CBigNum& b) { - bn = BN_new(); - if (!BN_copy(bn, b.bn)) + BIGNUM *dup = BN_dup(b.bn); + if (!dup) { - BN_clear_free(bn); - throw bignum_error("CBigNum::CBigNum(const CBigNum&) : BN_copy failed"); + throw bignum_error("CBigNum::CBigNum(const CBigNum&) : BN_dup failed"); } + bn = dup; } CBigNum& operator=(const CBigNum& b) { - bn = BN_new(); - if (!BN_copy(bn, b.bn)) - throw bignum_error("CBigNum::operator= : BN_copy failed"); + BIGNUM *dup = BN_dup(b.bn); + if (!dup) + { + throw bignum_error("CBigNum::operator= : BN_dup failed"); + } + bn = dup; return (*this); } + CBigNum(const BIGNUM *bnp) { + BIGNUM *dup = BN_dup(bnp); + if (!dup) + { + throw bignum_error("CBigNum::CBigNum(const BIGNUM*) : BN_dup failed"); + } + bn = dup; + } + ~CBigNum() { BN_clear_free(bn); @@ -466,7 +478,7 @@ public: } BIGNUM* get() const { - return bn; + return BN_dup(bn); } unsigned int GetSerializeSize(int nType=0, int nVersion=PROTOCOL_VERSION) const