GNU bug report logs -
#49217
'shuf' returns nothing if the low range number is higher by 1 than the high number
Previous Next
Reported by: F8ER F8ER <the.f8er <at> gmail.com>
Date: Fri, 25 Jun 2021 04:14:02 UTC
Severity: normal
Done: Paul Eggert <eggert <at> cs.ucla.edu>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
"shuf -i 1-0" would mistakenly accept the invalid range
without an error message and produce no output. Other
invalid ranges, e.g., "shuf -i 2-0", would be detected
and produce an error message, non-zero exit code, and
no output.
Bug reported by "F8ER F8ER."
* src/shuf.c (main): Fix bug.
* tests/misc/shuf.sh: Add a test case for the bug.
---
src/shuf.c | 2 +-
tests/misc/shuf.sh | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/shuf.c b/src/shuf.c
index 1af1b533a..91430a88a 100644
--- a/src/shuf.c
+++ b/src/shuf.c
@@ -431,7 +431,7 @@ main (int argc, char **argv)
_("invalid input range"), 0);
n_lines = hi_input - lo_input + 1;
- invalid |= ((lo_input <= hi_input) == (n_lines == 0));
+ invalid |= (lo_input > hi_input);
if (invalid)
die (EXIT_FAILURE, errno, "%s: %s", _("invalid input range"),
quote (optarg));
diff --git a/tests/misc/shuf.sh b/tests/misc/shuf.sh
index 892386b3f..2a7cba4d3 100755
--- a/tests/misc/shuf.sh
+++ b/tests/misc/shuf.sh
@@ -95,7 +95,7 @@ test "$c" -eq 3 || { fail=1; echo "Multiple -n failed">&2 ; }
{ shuf -i0-9 -n10 -i8-90 || test $? -ne 1; } &&
{ fail=1; echo "shuf did not detect multiple -i usage.">&2 ; }
# Test invalid range
-for ARG in '1' 'A' '1-' '1-A'; do
+for ARG in '1' 'A' '1-' '1-A' '1-0' '2-0'; do
{ shuf -i$ARG || test $? -ne 1; } &&
{ fail=1; echo "shuf did not detect erroneous -i$ARG usage.">&2 ; }
done
--
2.17.1
This bug report was last modified 3 years and 326 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.