]> Cypherpunks repositories - keks.git/commitdiff
Do not modify big.Int during encoding
authorSergey Matveev <stargrave@stargrave.org>
Tue, 14 Jan 2025 10:20:55 +0000 (13:20 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Tue, 14 Jan 2025 12:35:59 +0000 (15:35 +0300)
go/atom-encode.go

index 4c5876a031a5f876ead5a74668b7279bbd53bbc025363f329c748bd14c1a8f44..d69a46e76b75b7703f7053c489c8804a0f0e95cc934607a9501d00882bf4a226 100644 (file)
@@ -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 {