]> Cypherpunks repositories - gostls13.git/commit
math/big: add comprehensive aliasing tests (and minor fixes to Exp, Rand)
authorFilippo Valsorda <filippo@golang.org>
Thu, 4 Apr 2019 16:48:58 +0000 (12:48 -0400)
committerGopher Robot <gobot@golang.org>
Wed, 27 Apr 2022 17:24:48 +0000 (17:24 +0000)
commit89044b6d423a07bea3b6f80210f780e859dd2700
tree8050b5a45a02162f3b91ed7b45737a8b74a288c0
parentf0ee7fda636408b4f04ca3f3b11788f662c90610
math/big: add comprehensive aliasing tests (and minor fixes to Exp, Rand)

TestAlias checks systematically for aliasing issues, where passing the
same value for an argument and the receiver leads to incorrect results.

We had a number of issues like that over the years:

    - #31084: Lsh on arm64
    - #30217: GCD
    - #22830: Exp due to divLarge
    - #22265: ModSqrt
    - #20490: Add and Sub
    - #11284: GCD

This CL also fixes two new minor bugs that the test found. A wrong
result would be returned by

    - Exp when the modulo and the receiver alias
    - Rand when the limit is negative and it aliases the receiver

The test runs in ~0.05s with the default -quickchecks value.

Change-Id: I8354069ec9886e40c60f2642342ee08e604befb7
Reviewed-on: https://go-review.googlesource.com/c/go/+/168257
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <valsorda@google.com>
Reviewed-by: Roland Shoemaker <roland@golang.org>
Auto-Submit: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
src/math/big/alias_test.go [new file with mode: 0644]
src/math/big/int.go