diff options
author | Conrad Meyer <cem@FreeBSD.org> | 2020-01-16 21:38:44 +0000 |
---|---|---|
committer | Conrad Meyer <cem@FreeBSD.org> | 2020-01-16 21:38:44 +0000 |
commit | 92f7ba208c63b09aa8b077761a6734ccde7efda7 (patch) | |
tree | 0190cf1f577f554032bb0f254cdaf57c0338b08a /usr.bin/random | |
parent | 1137d1a7e575a897d6d7d5784c4c01498c419d9b (diff) | |
download | src-92f7ba208c63b09aa8b077761a6734ccde7efda7.tar.gz src-92f7ba208c63b09aa8b077761a6734ccde7efda7.zip |
random(6): Fix off-by-one
After r355693, random(6) -f sometimes fail to output all the lines of the
input file. This is because the range from which random indices are chosen
is too big, so occasionally the random selection doesn't correspond to any
line and nothing gets printed.
(Ed. note: Mea culpa. Working on r355693, I was confused by the sometime
use of 1-indexing, sometimes 0-indexing in randomize_fd().)
Submitted by: Ryan Moeller <ryan AT freqlabs.com>
X-MFC-With: r355693
Sponsored by: iXsystems, Inc.
Differential Revision: https://reviews.freebsd.org/D23199
Notes
Notes:
svn path=/head/; revision=356810
Diffstat (limited to 'usr.bin/random')
-rw-r--r-- | usr.bin/random/randomize_fd.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/usr.bin/random/randomize_fd.c b/usr.bin/random/randomize_fd.c index 7ee41cd99bc9..21075f301dd4 100644 --- a/usr.bin/random/randomize_fd.c +++ b/usr.bin/random/randomize_fd.c @@ -211,7 +211,7 @@ make_token: free(buf); for (i = numnode; i > 0; i--) { - selected = arc4random_uniform(numnode + 1); + selected = arc4random_uniform(numnode); for (j = 0, prev = n = rand_root; n != NULL; j++, prev = n, n = n->next) { if (j == selected) { |