mirror of
https://github.com/shopspring/decimal.git
synced 2024-11-22 12:30:49 +01:00
Allocate new(big.Int) in Copy method to deeply clone it (#278)
This commit is contained in:
parent
f55dd56454
commit
6926256b71
2 changed files with 5 additions and 1 deletions
|
@ -418,7 +418,7 @@ func NewFromFloatWithExponent(value float64, exp int32) Decimal {
|
|||
func (d Decimal) Copy() Decimal {
|
||||
d.ensureInitialized()
|
||||
return Decimal{
|
||||
value: &(*d.value),
|
||||
value: new(big.Int).Set(d.value),
|
||||
exp: d.exp,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -560,6 +560,10 @@ func TestCopy(t *testing.T) {
|
|||
origin := New(1, 0)
|
||||
cpy := origin.Copy()
|
||||
|
||||
if origin.value == cpy.value {
|
||||
t.Error("expecting copy and origin to have different value pointers")
|
||||
}
|
||||
|
||||
if cpy.Cmp(origin) != 0 {
|
||||
t.Error("expecting copy and origin to be equals, but they are not")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue