FAQ
Reviewers: golang-dev1,

Message:
Hello [email protected] (cc: [email protected]),

I'd like you to review this change to
https://go.googlecode.com/hg/


Description:
crypto/rand: better panic message for invalid Int argument.

Also document the panic to be consistent with math/rand.

Fixes issue 5187.

Please review this at https://codereview.appspot.com/8303043/

Affected files:
M src/pkg/crypto/rand/util.go


Index: src/pkg/crypto/rand/util.go
===================================================================
--- a/src/pkg/crypto/rand/util.go
+++ b/src/pkg/crypto/rand/util.go
@@ -100,8 +100,11 @@
}
}

-// Int returns a uniform random value in [0, max).
+// Int returns a uniform random value in [0, max). It panics if max <= 0.
func Int(rand io.Reader, max *big.Int) (n *big.Int, err error) {
+ if max.Sign() <= 0 {
+ panic("crypto/rand: argument to Int is <= 0")
+ }
k := (max.BitLen() + 7) / 8

// b is the number of bits in the most significant byte of max.


--

---
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Dave at Apr 3, 2013 at 6:18 am
    Thank you. Leaving for the release candidate masters to decide if it
    makes the cut.


    https://codereview.appspot.com/8303043/diff/5001/src/pkg/crypto/rand/util.go
    File src/pkg/crypto/rand/util.go (right):

    https://codereview.appspot.com/8303043/diff/5001/src/pkg/crypto/rand/util.go#newcode106
    src/pkg/crypto/rand/util.go:106: panic("crypto/rand: argument to Int is
    <= 0")
    Could you change math/rand at the same time to use this wording, I think
    it is an improvement over what exists now.

    https://codereview.appspot.com/8303043/

    --

    ---
    You received this message because you are subscribed to the Google Groups "golang-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
    For more options, visit https://groups.google.com/groups/opt_out.
  • Brad Fitzpatrick at Apr 3, 2013 at 7:50 am
    LGTM

    Don't care about nil too?


    On Tue, Apr 2, 2013 at 11:15 PM, wrote:

    Reviewers: golang-dev1,

    Message:
    Hello [email protected] (cc: [email protected]),

    I'd like you to review this change to
    https://go.googlecode.com/hg/


    Description:
    crypto/rand: better panic message for invalid Int argument.

    Also document the panic to be consistent with math/rand.

    Fixes issue 5187.

    Please review this at https://codereview.appspot.**com/8303043/<https://codereview.appspot.com/8303043/>

    Affected files:
    M src/pkg/crypto/rand/util.go


    Index: src/pkg/crypto/rand/util.go
    ==============================**==============================**=======
    --- a/src/pkg/crypto/rand/util.go
    +++ b/src/pkg/crypto/rand/util.go
    @@ -100,8 +100,11 @@
    }
    }

    -// Int returns a uniform random value in [0, max).
    +// Int returns a uniform random value in [0, max). It panics if max <= 0.
    func Int(rand io.Reader, max *big.Int) (n *big.Int, err error) {
    + if max.Sign() <= 0 {
    + panic("crypto/rand: argument to Int is <= 0")
    + }
    k := (max.BitLen() + 7) / 8

    // b is the number of bits in the most significant byte of max.


    --

    ---You received this message because you are subscribed to the Google
    Groups "golang-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-dev+unsubscribe@**googlegroups.com<golang-dev%[email protected]>
    .
    For more options, visit https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
    .

    --

    ---
    You received this message because you are subscribed to the Google Groups "golang-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedApr 3, '13 at 6:15a
activeApr 3, '13 at 7:50a
posts3
users3
websitegolang.org

People

Translate

site design / logo © 2023 Grokbase