Page MenuHomeFreeBSD

random(6): Fix off-by-one error
ClosedPublic

Authored by freqlabs on Jan 16 2020, 9:32 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Apr 27, 3:24 PM
Unknown Object (File)
Sat, Apr 27, 3:24 PM
Unknown Object (File)
Sat, Apr 27, 3:24 PM
Unknown Object (File)
Sat, Apr 27, 1:52 PM
Unknown Object (File)
Jan 18 2024, 9:30 AM
Unknown Object (File)
Jan 9 2024, 10:14 PM
Unknown Object (File)
Dec 22 2023, 10:20 PM
Unknown Object (File)
Aug 30 2023, 6:33 PM
Subscribers

Details

Summary

After rS355693 random -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.

Sponsored by: iXsystems, Inc.

Test Plan
for _ in $(seq 10); do
    seq 0 1 | random -f -
done

Before:

1
2
1
0
2
1
2
1
2
1

After:

2
2
2
2
2
2
2
2
2
2

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

freqlabs edited the test plan for this revision. (Show Details)
freqlabs edited the test plan for this revision. (Show Details)
This revision is now accepted and ready to land.Jan 16 2020, 10:19 AM

@cem Will you commit this for me? I don't have the bit. Thanks!

Yep no problem. Thanks for the report and patch!

This revision was automatically updated to reflect the committed changes.