From: Sergey Matveev Date: Tue, 14 Jan 2025 10:20:55 +0000 (+0300) Subject: Do not modify big.Int during encoding X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f71a0018f2f8e562a2fc4d8fe08d56c6fa19d1c8bbbb0209bb91618bfdd10f66;p=keks.git Do not modify big.Int during encoding --- 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 {