ls: fix spurious output with -Z
[coreutils.git] / tests / cut / cut-huge-range.sh
blob75982b29e017d16f32f3fc1bb7052bf95ba5a084
1 #!/bin/sh
2 # Ensure that cut does not allocate mem for large ranges
4 # Copyright (C) 2012-2024 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_ 'shell lacks ulimit, or ASAN enabled'
26 # Ensure we can cut up to our sentinel value.
27 # Don't use expr to subtract one,
28 # since UINTMAX_MAX may exceed its maximum value.
29 CUT_MAX=$(expr $UINTMAX_MAX - 1) || framework_failure_
31 # From coreutils-8.10 through 8.20, this would make cut try to allocate
32 # a 256MiB bit vector.
33 (ulimit -v $vm && cut -b$CUT_MAX- /dev/null > err 2>&1) || fail=1
35 # Up to and including coreutils-8.21, cut would allocate possibly needed
36 # memory upfront. Subsequently extra memory is no longer needed.
37 (ulimit -v $vm && cut -b1-$CUT_MAX /dev/null >> err 2>&1) || fail=1
39 # Explicitly disallow values above CUT_MAX
40 (ulimit -v $vm && returns_ 1 cut -b$UINTMAX_MAX /dev/null 2>/dev/null) ||
41 fail=1
42 (ulimit -v $vm && returns_ 1 cut -b$UINTMAX_OFLOW /dev/null 2>/dev/null) ||
43 fail=1
45 compare /dev/null err || fail=1
47 Exit $fail