From 3868940cdd7294e8db0acf28108a9ace9ff7a36d Mon Sep 17 00:00:00 2001 From: Bastien Gysler Date: Tue, 9 May 2017 14:51:20 +0200 Subject: [PATCH] Fix GobDecode (#51) This commit fixes GobDecode, which were mutating a copy of the receiver, rather than the intended pointed struct. --- decimal.go | 2 +- decimal_test.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/decimal.go b/decimal.go index 2caf597..5fcb628 100644 --- a/decimal.go +++ b/decimal.go @@ -697,7 +697,7 @@ func (d Decimal) GobEncode() ([]byte, error) { } // GobDecode implements the gob.GobDecoder interface for gob serialization. -func (d Decimal) GobDecode(data []byte) error { +func (d *Decimal) GobDecode(data []byte) error { return d.UnmarshalBinary(data) } diff --git a/decimal_test.go b/decimal_test.go index bdfc27c..a0ad37c 100644 --- a/decimal_test.go +++ b/decimal_test.go @@ -1637,5 +1637,10 @@ func TestGobEncode(t *testing.T) { if eq != true { t.Errorf("Encoding then decoding mutated Decimal") } + + eq = d1.Equal(d3) + if eq != true { + t.Errorf("Error gobencoding/decoding %v, got %v", d1, d3) + } } }