maint: update all copyright year number ranges
[coreutils.git] / tests / misc / cut-huge-range.sh
blobc015ac58cbe5ff72f4dc72dc523eb1744fc8fb4c
1 #!/bin/sh
2 # Ensure that cut does not allocate mem for large ranges
4 # Copyright (C) 2012-2017 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20 print_ver_ cut
21 getlimits_
23 vm=$(get_min_ulimit_v_ cut -b1 /dev/null) \
24 || skip_ "this shell lacks ulimit support"
26 # sed script to subtract one from the input.
27 # Each input line should consist of a positive decimal number.
28 # Each output line's number is one less than the input's.
29 # There's no limit (other than line length) on the number's magnitude.
30 subtract_one='
31 s/$/@/
32 : again
33 s/0@/@9/
34 s/1@/0/
35 s/2@/1/
36 s/3@/2/
37 s/4@/3/
38 s/5@/4/
39 s/6@/5/
40 s/7@/6/
41 s/8@/7/
42 s/9@/8/
43 t again
46 # Ensure we can cut up to our sentinel value.
47 # This is currently SIZE_MAX, but could be raised to UINTMAX_MAX
48 # if we didn't allocate memory for each line as a unit.
49 # Don't use expr to subtract one,
50 # since SIZE_MAX may exceed its maximum value.
51 CUT_MAX=$(echo $SIZE_MAX | sed "$subtract_one")
53 # From coreutils-8.10 through 8.20, this would make cut try to allocate
54 # a 256MiB bit vector.
55 (ulimit -v $vm && cut -b$CUT_MAX- /dev/null > err 2>&1) || fail=1
57 # Up to and including coreutils-8.21, cut would allocate possibly needed
58 # memory upfront. Subsequently extra memory is no longer needed.
59 (ulimit -v $vm && cut -b1-$CUT_MAX /dev/null >> err 2>&1) || fail=1
61 # Explicitly disallow values above CUT_MAX
62 (ulimit -v $vm && returns_ 1 cut -b$SIZE_MAX /dev/null 2>/dev/null) || fail=1
63 (ulimit -v $vm && returns_ 1 cut -b$SIZE_OFLOW /dev/null 2>/dev/null) || fail=1
65 compare /dev/null err || fail=1
67 Exit $fail