From f71a0018f2f8e562a2fc4d8fe08d56c6fa19d1c8bbbb0209bb91618bfdd10f66 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Tue, 14 Jan 2025 13:20:55 +0300 Subject: [PATCH] Do not modify big.Int during encoding --- go/atom-encode.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/go/atom-encode.go b/go/atom-encode.go index 4c5876a..d69a46e 100644 --- a/go/atom-encode.go +++ b/go/atom-encode.go @@ -100,9 +100,8 @@ func BigIntEncode(w io.Writer, v *big.Int) (written int64, err error) { if v.Sign() >= 0 { _, err = w.Write([]byte{byte(AtomPInt)}) } else { - n1 := big.NewInt(-1) - v = v.Abs(v) - v = v.Add(v, n1) + n := new(big.Int).Abs(v) + v = n.Sub(n, big.NewInt(1)) _, err = w.Write([]byte{byte(AtomNInt)}) } if err != nil { -- 2.50.0