tests: add test for locale decimal processing
[coreutils.git] / tests / misc / cut-huge-range.sh
blobbebcd0925a6a991bfc40488d2488d669a9988798
1 #!/bin/sh
2 # Ensure that cut does not allocate mem for large ranges
4 # Copyright (C) 2012-2019 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 <https://www.gnu.org/licenses/>.
19 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20 print_ver_ cut
21 getlimits_
23 vm=$(get_min_ulimit_v_ returns_ 0 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 # Don't use expr to subtract one,
48 # since UINTMAX_MAX may exceed its maximum value.
49 CUT_MAX=$(echo $UINTMAX_MAX | sed "$subtract_one")
51 # From coreutils-8.10 through 8.20, this would make cut try to allocate
52 # a 256MiB bit vector.
53 (ulimit -v $vm && cut -b$CUT_MAX- /dev/null > err 2>&1) || fail=1
55 # Up to and including coreutils-8.21, cut would allocate possibly needed
56 # memory upfront. Subsequently extra memory is no longer needed.
57 (ulimit -v $vm && cut -b1-$CUT_MAX /dev/null >> err 2>&1) || fail=1
59 # Explicitly disallow values above CUT_MAX
60 (ulimit -v $vm && returns_ 1 cut -b$UINTMAX_MAX /dev/null 2>/dev/null) ||
61 fail=1
62 (ulimit -v $vm && returns_ 1 cut -b$UINTMAX_OFLOW /dev/null 2>/dev/null) ||
63 fail=1
65 compare /dev/null err || fail=1
67 Exit $fail