math/mprand.[ch], rand/grand.c: Check range of arguments.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 11 Sep 2016 13:29:49 +0000 (14:29 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 11 Sep 2016 13:29:49 +0000 (14:29 +0100)
commit423acb9483f672df5cf220e386b7d85e35b95fb8
treeb5ae8ab1f12d41d491508f9240687b90ded58d9e
parentc973f431a370a3adbcb3c94f76dc6896a7279235
math/mprand.[ch], rand/grand.c: Check range of arguments.

  * mprand: It doesn't make sense to ask for a zero-bit integer whose
    low bit is set; or, indeed, a four-bit integer whose fourth bit is
    set.  So check the mask against the bit length.

  * mprand: On the other hand, it /does/ make sense to ask for a
    zero-bit integer, and the answer is simply zero.  But the code used
    to segfault.  Fix this.

  * mprand_range, grand_defaultrange: It doesn't make sense to ask for
    an integer in [0, 0), because there aren't any.  Check before
    trying.
math/mprand.c
math/mprand.h
rand/grand.c