Submitted By: Miklos Karacsony <mkaracsony81 at gmail dot com>
Date: 2014-04-22
Initial Package Version: 8.22
Upstream Status: Applied
Origin: Upstream
Description: shuf: with -r, don't dump core if the input is empty
diff --git a/NEWS b/NEWS
index e72942b..2df246d 100644
a
|
b
|
GNU coreutils NEWS -*- outline -*-
|
22 | 22 | it would display an error, requiring --no-dereference to avoid the issue. |
23 | 23 | [bug introduced in coreutils-5.3.0] |
24 | 24 | |
| 25 | shuf -r no longer dumps core if the input is empty. |
| 26 | [bug introduced in coreutils-8.22] |
| 27 | |
25 | 28 | ** New features |
26 | 29 | |
27 | 30 | od accepts a new option: --endian=TYPE to handle inputs with different byte |
diff --git a/src/shuf.c b/src/shuf.c
index d4641fe..2a91072 100644
a
|
b
|
main (int argc, char **argv)
|
576 | 576 | /* Generate output according to requested method */ |
577 | 577 | if (repeat) |
578 | 578 | { |
579 | | if (input_range) |
580 | | i = write_random_numbers (randint_source, head_lines, |
581 | | lo_input, hi_input, eolbyte); |
| 579 | if (head_lines == 0) |
| 580 | i = 0; |
582 | 581 | else |
583 | | i = write_random_lines (randint_source, head_lines, line, n_lines); |
| 582 | { |
| 583 | if (n_lines == 0) |
| 584 | error (EXIT_FAILURE, 0, _("No lines to repeat")); |
| 585 | if (input_range) |
| 586 | i = write_random_numbers (randint_source, head_lines, |
| 587 | lo_input, hi_input, eolbyte); |
| 588 | else |
| 589 | i = write_random_lines (randint_source, head_lines, line, n_lines); |
| 590 | } |
584 | 591 | } |
585 | 592 | else |
586 | 593 | { |
diff --git a/tests/misc/shuf.sh b/tests/misc/shuf.sh
index d3ea1f2..d7251d1 100755
a
|
b
|
compare in out1 || { fail=1; echo "not a permutation" 1>&2; }
|
43 | 43 | t=$(shuf -e a b c d e | sort | fmt) |
44 | 44 | test "$t" = 'a b c d e' || { fail=1; echo "not a permutation" 1>&2; } |
45 | 45 | |
| 46 | # coreutils-8.22 dumps core. |
| 47 | shuf -er |
| 48 | test $? -eq 1 || fail=1 |
| 49 | |
46 | 50 | # Before coreutils-6.3, this would infloop. |
47 | 51 | # "seq 1860" produces 8193 (8K + 1) bytes of output. |
48 | 52 | seq 1860 | shuf > /dev/null || fail=1 |