diff options
author | Theo Buehler <tb@cvs.openbsd.org> | 2016-07-17 04:04:47 +0000 |
---|---|---|
committer | Theo Buehler <tb@cvs.openbsd.org> | 2016-07-17 04:04:47 +0000 |
commit | 1dfef459457e5cc940a0fae32fe00da0fa1ce333 (patch) | |
tree | a3a5b779433446b4befcd07a284fc0f192d6f6a7 /usr.bin/jot/jot.c | |
parent | 13657b84995128a97815becba738466c055cc0f6 (diff) |
1. Update manpage in view of the change of behavior I introduced in -r1.27.
The bounds are taken inclusive and -w %d doesn't change the output of
integer random sequences anymore. This is the same behavior as that
of Linux and NetBSD, but differs from FreeBSD and OS X.
Issue reported by Philippe Meunier on misc@.
2 Fix a bug from the same commit observed by Otto: if the precision is 0,
values may be printed out of bounds. Fall back to the old behavior if at
least one bound isn't an integer.
General agreement expressed by otto@, tedu@, jmc@, sobrado@
Help with checking other operating systems by sobrado@.
Manpage ok jmc@.
Bugfix discussed with otto@ on icb
Diffstat (limited to 'usr.bin/jot/jot.c')
-rw-r--r-- | usr.bin/jot/jot.c | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/usr.bin/jot/jot.c b/usr.bin/jot/jot.c index e4fdade12f9..08da69f270b 100644 --- a/usr.bin/jot/jot.c +++ b/usr.bin/jot/jot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: jot.c,v 1.27 2016/01/10 01:15:52 tb Exp $ */ +/* $OpenBSD: jot.c,v 1.28 2016/07/17 04:04:46 tb Exp $ */ /* $NetBSD: jot.c,v 1.3 1994/12/02 20:29:43 pk Exp $ */ /*- @@ -277,9 +277,6 @@ main(int argc, char *argv[]) if (prec > 9) /* pow(10, prec) > UINT32_MAX */ errx(1, "requested precision too large"); - while (prec-- > 0) - pow10 *= 10; - if (ender < begin) { x = begin; begin = ender; @@ -287,16 +284,22 @@ main(int argc, char *argv[]) } x = ender - begin; - /* - * If pow10 * (ender - begin) is an integer, use - * arc4random_uniform(). - */ - use_unif = fmod(pow10 * (ender - begin), 1) == 0; - if (use_unif) { - uintx = pow10 * (ender - begin); - if (uintx >= UINT32_MAX) - errx(1, "requested range too large"); - uintx++; + if (prec == 0 && (fmod(ender, 1) != 0 || fmod(begin, 1) != 0)) + use_unif = 0; + else { + while (prec-- > 0) + pow10 *= 10; + /* + * If pow10 * (ender - begin) is an integer, use + * arc4random_uniform(). + */ + use_unif = fmod(pow10 * (ender - begin), 1) == 0; + if (use_unif) { + uintx = pow10 * (ender - begin); + if (uintx >= UINT32_MAX) + errx(1, "requested range too large"); + uintx++; + } } for (i = 1; i <= reps || infinity; i++) { |