]> git.ipfire.org Git - thirdparty/bash.git/blob - tests/printf7.sub
renamed several functions beginning with legal_; changed all callers
[thirdparty/bash.git] / tests / printf7.sub
1 # This program is free software: you can redistribute it and/or modify
2 # it under the terms of the GNU General Public License as published by
3 # the Free Software Foundation, either version 3 of the License, or
4 # (at your option) any later version.
5 #
6 # This program is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 # GNU General Public License for more details.
10 #
11 # You should have received a copy of the GNU General Public License
12 # along with this program. If not, see <http://www.gnu.org/licenses/>.
13 #
14
15 # tests of integer overflow for field width and precision arguments
16 INT_MAX=$(getconf INT_MAX)
17 TOOBIG=$(( $INT_MAX * 10 ))
18
19 printf '[%*s]\n' "${TOOBIG}"
20 printf '[%*s]\n' "${TOOBIG}" X
21
22 printf -v VAR '[%*s]' "${TOOBIG}"
23 echo VAR="$VAR"
24 unset -v VAR
25 printf -v VAR '[%*s]' "${TOOBIG}" X
26 echo VAR="$VAR"
27 unset -v VAR
28
29 TOOBIG=9223372036854775825
30
31 printf '[%*s]\n' "${TOOBIG}"
32 printf '[%*s]\n' "${TOOBIG}" X
33
34 printf -v VAR '[%*s]' "${TOOBIG}"
35 echo VAR="$VAR"
36 unset -v VAR
37 printf -v VAR '[%*s]' "${TOOBIG}" X
38 echo VAR="$VAR"
39 unset -v VAR
40
41 TOOBIG=$(( $INT_MAX * 10 ))
42
43 printf '[%.*s]\n' "${TOOBIG}"
44 printf '[%.*s]\n' "${TOOBIG}" X
45
46 printf -v VAR '[%.*s]' "${TOOBIG}"
47 echo VAR="$VAR"
48 unset -v VAR
49 printf -v VAR '[%.*s]' "${TOOBIG}" X
50 echo VAR="$VAR"
51 unset -v VAR
52
53 TOOBIG=9223372036854775825
54
55 printf '[%.*s]\n' "${TOOBIG}"
56 printf '[%.*s]\n' "${TOOBIG}" X
57
58 printf -v VAR '[%.*s]' "${TOOBIG}"
59 echo VAR="$VAR"
60 unset -v VAR
61 printf -v VAR '[%.*s]' "${TOOBIG}" X
62 echo VAR="$VAR"
63 unset -v VAR
64
65 # out of range inline precisions
66
67 # can't test %s, too many varying implementations
68 #printf "%.${TOOBIG}s\n" XY
69 printf -v VAR "%.${TOOBIG}s\n" XY
70 echo $VAR
71 printf "%.${TOOBIG}Q\n" XY