Skip to content

Commit 08b17de

Browse files
committed
[arith_uint256] Do not destroy *this content if passed-in operator may reference it
1 parent bf3353d commit 08b17de

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/arith_uint256.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,16 @@ base_uint<BITS>& base_uint<BITS>::operator*=(uint32_t b32)
6969
template <unsigned int BITS>
7070
base_uint<BITS>& base_uint<BITS>::operator*=(const base_uint& b)
7171
{
72-
base_uint<BITS> a = *this;
73-
*this = 0;
72+
base_uint<BITS> a;
7473
for (int j = 0; j < WIDTH; j++) {
7574
uint64_t carry = 0;
7675
for (int i = 0; i + j < WIDTH; i++) {
77-
uint64_t n = carry + pn[i + j] + (uint64_t)a.pn[j] * b.pn[i];
78-
pn[i + j] = n & 0xffffffff;
76+
uint64_t n = carry + a.pn[i + j] + (uint64_t)pn[j] * b.pn[i];
77+
a.pn[i + j] = n & 0xffffffff;
7978
carry = n >> 32;
8079
}
8180
}
81+
*this = a;
8282
return *this;
8383
}
8484

0 commit comments

Comments
 (0)