OpenCoverage

gm_loop.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/lib/glob/gm_loop.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* Copyright (C) 1991-2017 Free Software Foundation, Inc.-
2-
3 This file is part of GNU Bash, the Bourne Again SHell.-
4 -
5 Bash is free software: you can redistribute it and/or modify-
6 it under the terms of the GNU General Public License as published by-
7 the Free Software Foundation, either version 3 of the License, or-
8 (at your option) any later version.-
9-
10 Bash is distributed in the hope that it will be useful,-
11 but WITHOUT ANY WARRANTY; without even the implied warranty of-
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
13 GNU General Public License for more details.-
14-
15 You should have received a copy of the GNU General Public License-
16 along with Bash. If not, see <http://www.gnu.org/licenses/>.-
17*/-
18-
19#if EXTENDED_GLOB-
20int-
21EXTGLOB_PATTERN_P (pat)-
22 const CHAR *pat;-
23{-
24 switch (pat[0])-
25 {-
26 case L('*'):
executed 46858 times by 1 test: case '*':
Executed by:
  • Self test
never executed: case L'*':
0-46858
27 case L('+'):
executed 32 times by 1 test: case '+':
Executed by:
  • Self test
never executed: case L'+':
0-32
28 case L('!'):
executed 84 times by 1 test: case '!':
Executed by:
  • Self test
never executed: case L'!':
0-84
29 case L('@'):
executed 2240 times by 1 test: case '@':
Executed by:
  • Self test
never executed: case L'@':
0-2240
30 case L('?'):
executed 3364 times by 1 test: case '?':
Executed by:
  • Self test
never executed: case L'?':
0-3364
31 return (pat[1] == L('(')); /* ) */
executed 52578 times by 1 test: return (pat[1] == '(');
Executed by:
  • Self test
never executed: return (pat[1] == L'(');
0-52578
32 default:
executed 933804 times by 1 test: default:
Executed by:
  • Self test
never executed: default:
0-933804
33 return 0;
executed 933804 times by 1 test: return 0;
Executed by:
  • Self test
never executed: return 0;
0-933804
34 }-
35 -
36 return 0;
dead code: return 0;
dead code: return 0;
-
37}-
38#endif-
39-
40/* Return 1 of the first character of STRING could match the first-
41 character of pattern PAT. Compiled to both single and wiide character-
42 versions. FLAGS is a subset of strmatch flags; used to do case-insensitive-
43 matching for now. */-
44int-
45MATCH_PATTERN_CHAR (pat, string, flags)-
46 CHAR *pat, *string;-
47 int flags;-
48{-
49 CHAR c;-
50-
51 if (*string == 0)
*string == 0Description
TRUEevaluated 18 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 94174 times by 1 test
Evaluated by:
  • Self test
*string == 0Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
0-94174
52 return (*pat == L('*')); /* XXX - allow only * to match empty string */
executed 18 times by 1 test: return (*pat == '*');
Executed by:
  • Self test
never executed: return (*pat == L'*');
0-18
53-
54 switch (c = *pat++)-
55 {-
56 default:
executed 17893 times by 1 test: default:
Executed by:
  • Self test
executed 2 times by 1 test: default:
Executed by:
  • Self test
2-17893
57 return (FOLD(*string) == FOLD(c));
executed 17893 times by 1 test: return (((flags & (1 << 4)) ? ((1 && ((*__ctype_b_loc ())[(int) (( (unsigned char)(unsigned char)*string ))] & (unsigned short int) _ISupper) ) ? (__extension__ ({ int __res; if (sizeof ( (unsigned char)*string ) > 1) { if (__builtin_constant_p ( (unsigne...d char)c ); __res = __c < -128 || __c > 255 ? __c : (*__ctype_tolower_loc ())[__c]; } else __res = tolower ( (unsigned char)c ); } else __res = (*__ctype_tolower_loc ())[(int) ( (unsigned char)c )]; __res; })) : ((unsigned char)c)) : ((unsigned char)c)));
Executed by:
  • Self test
never executed: end of block
never executed: __res = tolower ( (unsigned char)*string );
never executed: __res = (*__ctype_tolower_loc ())[(int) ( (unsigned char)*string )];
never executed: end of block
never executed: __res = tolower ( (unsigned char)c );
executed 6 times by 1 test: __res = (*__ctype_tolower_loc ())[(int) ( (unsigned char)c )];
Executed by:
  • Self test
executed 2 times by 1 test: return (((flags & (1 << 4)) && iswupper (*string) ? towlower (*string) : (*string)) == ((flags & (1 << 4)) && iswupper (c) ? towlower (c) : (c)));
Executed by:
  • Self test
sizeof ( (unsi...)*string ) > 1Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons...char)*string )Description
TRUEnever evaluated
FALSEnever evaluated
sizeof ( (unsi...d char)c ) > 1Description
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
__builtin_cons...igned char)c )Description
TRUEnever evaluated
FALSEnever evaluated
__c < -128Description
TRUEnever evaluated
FALSEnever evaluated
__c > 255Description
TRUEnever evaluated
FALSEnever evaluated
__c < -128Description
TRUEnever evaluated
FALSEnever evaluated
__c > 255Description
TRUEnever evaluated
FALSEnever evaluated
0-17893
58 case L('\\'):
executed 486 times by 1 test: case '\\':
Executed by:
  • Self test
never executed: case L'\\':
0-486
59 return (FOLD(*string) == FOLD(*pat));
executed 486 times by 1 test: return (((flags & (1 << 4)) ? ((1 && ((*__ctype_b_loc ())[(int) (( (unsigned char)(unsigned char)*string ))] & (unsigned short int) _ISupper) ) ? (__extension__ ({ int __res; if (sizeof ( (unsigned char)*string ) > 1) { if (__builtin_constant_p ( (unsigne...__res = __c < -128 || __c > 255 ? __c : (*__ctype_tolower_loc ())[__c]; } else __res = tolower ( (unsigned char)*pat ); } else __res = (*__ctype_tolower_loc ())[(int) ( (unsigned char)*pat )]; __res; })) : ((unsigned char)*pat)) : ((unsigned char)*pat)));
Executed by:
  • Self test
never executed: end of block
never executed: __res = tolower ( (unsigned char)*string );
never executed: __res = (*__ctype_tolower_loc ())[(int) ( (unsigned char)*string )];
never executed: end of block
never executed: __res = tolower ( (unsigned char)*pat );
never executed: __res = (*__ctype_tolower_loc ())[(int) ( (unsigned char)*pat )];
never executed: return (((flags & (1 << 4)) && iswupper (*string) ? towlower (*string) : (*string)) == ((flags & (1 << 4)) && iswupper (*pat) ? towlower (*pat) : (*pat)));
sizeof ( (unsi...)*string ) > 1Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons...char)*string )Description
TRUEnever evaluated
FALSEnever evaluated
sizeof ( (unsi...har)*pat ) > 1Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons...ed char)*pat )Description
TRUEnever evaluated
FALSEnever evaluated
__c < -128Description
TRUEnever evaluated
FALSEnever evaluated
__c > 255Description
TRUEnever evaluated
FALSEnever evaluated
__c < -128Description
TRUEnever evaluated
FALSEnever evaluated
__c > 255Description
TRUEnever evaluated
FALSEnever evaluated
0-486
60 case L('?'):
executed 16094 times by 1 test: case '?':
Executed by:
  • Self test
never executed: case L'?':
0-16094
61 return (*pat == L('(') ? 1 : (*string != L'\0'));
executed 16094 times by 1 test: return (*pat == '(' ? 1 : (*string != L'\0'));
Executed by:
  • Self test
never executed: return (*pat == L'(' ? 1 : (*string != L'\0'));
0-16094
62 case L('*'):
executed 193 times by 1 test: case '*':
Executed by:
  • Self test
never executed: case L'*':
0-193
63 return (1);
executed 193 times by 1 test: return (1);
Executed by:
  • Self test
never executed: return (1);
0-193
64 case L('+'):
never executed: case '+':
never executed: case L'+':
0
65 case L('!'):
never executed: case '!':
never executed: case L'!':
0
66 case L('@'):
never executed: case '@':
never executed: case L'@':
0
67 return (*pat == L('(') ? 1 : (FOLD(*string) == FOLD(c)));
never executed: return (*pat == '(' ? 1 : (((flags & (1 << 4)) ? ((1 && ((*__ctype_b_loc ())[(int) (( (unsigned char)(unsigned char)*string ))] & (unsigned short int) _ISupper) ) ? (__extension__ ({ int __res; if (sizeof ( (unsigned char)*string ) > 1) { if (__builtin_co... char)c ); __res = __c < -128 || __c > 255 ? __c : (*__ctype_tolower_loc ())[__c]; } else __res = tolower ( (unsigned char)c ); } else __res = (*__ctype_tolower_loc ())[(int) ( (unsigned char)c )]; __res; })) : ((unsigned char)c)) : ((unsigned char)c))));
never executed: end of block
never executed: __res = tolower ( (unsigned char)*string );
never executed: __res = (*__ctype_tolower_loc ())[(int) ( (unsigned char)*string )];
never executed: end of block
never executed: __res = tolower ( (unsigned char)c );
never executed: __res = (*__ctype_tolower_loc ())[(int) ( (unsigned char)c )];
never executed: return (*pat == L'(' ? 1 : (((flags & (1 << 4)) && iswupper (*string) ? towlower (*string) : (*string)) == ((flags & (1 << 4)) && iswupper (c) ? towlower (c) : (c))));
sizeof ( (unsi...)*string ) > 1Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons...char)*string )Description
TRUEnever evaluated
FALSEnever evaluated
sizeof ( (unsi...d char)c ) > 1Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons...igned char)c )Description
TRUEnever evaluated
FALSEnever evaluated
__c < -128Description
TRUEnever evaluated
FALSEnever evaluated
__c > 255Description
TRUEnever evaluated
FALSEnever evaluated
__c < -128Description
TRUEnever evaluated
FALSEnever evaluated
__c > 255Description
TRUEnever evaluated
FALSEnever evaluated
0
68 case L('['):
executed 59508 times by 1 test: case '[':
Executed by:
  • Self test
never executed: case L'[':
0-59508
69 return (*string != L('\0'));
executed 59508 times by 1 test: return (*string != '\0');
Executed by:
  • Self test
never executed: return (*string != L'\0');
0-59508
70 }-
71}-
72-
73int-
74MATCHLEN (pat, max)-
75 CHAR *pat;-
76 size_t max;-
77{-
78 CHAR c;-
79 int matlen, bracklen, t, in_cclass, in_collsym, in_equiv;-
80-
81 if (*pat == 0)
*pat == 0Description
TRUEnever evaluated
FALSEevaluated 59359 times by 1 test
Evaluated by:
  • Self test
*pat == 0Description
TRUEnever evaluated
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
0-59359
82 return (0);
never executed: return (0);
never executed: return (0);
0
83-
84 matlen = in_cclass = in_collsym = in_equiv = 0;-
85 while (c = *pat++)
c = *pat++Description
TRUEevaluated 68045 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 59064 times by 1 test
Evaluated by:
  • Self test
c = *pat++Description
TRUEevaluated 14 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
7-68045
86 {-
87 switch (c)-
88 {-
89 default:
executed 11173 times by 1 test: default:
Executed by:
  • Self test
executed 14 times by 1 test: default:
Executed by:
  • Self test
14-11173
90 matlen++;-
91 break;
executed 11173 times by 1 test: break;
Executed by:
  • Self test
executed 14 times by 1 test: break;
Executed by:
  • Self test
14-11173
92 case L('\\'):
executed 197 times by 1 test: case '\\':
Executed by:
  • Self test
never executed: case L'\\':
0-197
93 if (*pat == 0)
*pat == 0Description
TRUEnever evaluated
FALSEevaluated 197 times by 1 test
Evaluated by:
  • Self test
*pat == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-197
94 return ++matlen;
never executed: return ++matlen;
never executed: return ++matlen;
0
95 else-
96 {-
97 matlen++;-
98 pat++;-
99 }
executed 197 times by 1 test: end of block
Executed by:
  • Self test
never executed: end of block
0-197
100 break;
executed 197 times by 1 test: break;
Executed by:
  • Self test
never executed: break;
0-197
101 case L('?'):
executed 2928 times by 1 test: case '?':
Executed by:
  • Self test
never executed: case L'?':
0-2928
102 if (*pat == LPAREN)
*pat == '('Description
TRUEnever evaluated
FALSEevaluated 2928 times by 1 test
Evaluated by:
  • Self test
*pat == L'('Description
TRUEnever evaluated
FALSEnever evaluated
0-2928
103 return (matlen = -1); /* XXX for now */
never executed: return (matlen = -1);
never executed: return (matlen = -1);
0
104 else-
105 matlen++;
executed 2928 times by 1 test: matlen++;
Executed by:
  • Self test
never executed: matlen++;
0-2928
106 break;
executed 2928 times by 1 test: break;
Executed by:
  • Self test
never executed: break;
0-2928
107 case L('*'):
executed 295 times by 1 test: case '*':
Executed by:
  • Self test
never executed: case L'*':
0-295
108 return (matlen = -1);
executed 295 times by 1 test: return (matlen = -1);
Executed by:
  • Self test
never executed: return (matlen = -1);
0-295
109 case L('+'):
never executed: case '+':
never executed: case L'+':
0
110 case L('!'):
never executed: case '!':
never executed: case L'!':
0
111 case L('@'):
never executed: case '@':
never executed: case L'@':
0
112 if (*pat == LPAREN)
*pat == '('Description
TRUEnever evaluated
FALSEnever evaluated
*pat == L'('Description
TRUEnever evaluated
FALSEnever evaluated
0
113 return (matlen = -1); /* XXX for now */
never executed: return (matlen = -1);
never executed: return (matlen = -1);
0
114 else-
115 matlen++;
never executed: matlen++;
never executed: matlen++;
0
116 break;
never executed: break;
never executed: break;
0
117 case L('['):
executed 53452 times by 1 test: case '[':
Executed by:
  • Self test
never executed: case L'[':
0-53452
118 /* scan for ending `]', skipping over embedded [:...:] */-
119 bracklen = 1;-
120 c = *pat++;-
121 do-
122 {-
123 if (c == 0)
c == 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 213647 times by 1 test
Evaluated by:
  • Self test
c == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-213647
124 {-
125 pat--; /* back up to NUL */-
126 matlen += bracklen;-
127 goto bad_bracket;
executed 3 times by 1 test: goto bad_bracket;
Executed by:
  • Self test
never executed: goto bad_bracket;
0-3
128 }-
129 else if (c == L('\\'))
c == '\\'Description
TRUEevaluated 48 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 213599 times by 1 test
Evaluated by:
  • Self test
c == L'\\'Description
TRUEnever evaluated
FALSEnever evaluated
0-213599
130 {-
131 /* *pat == backslash-escaped character */-
132 bracklen++;-
133 /* If the backslash or backslash-escape ends the string,-
134 bail. The ++pat skips over the backslash escape */-
135 if (*pat == 0 || *++pat == 0)
*pat == 0Description
TRUEnever evaluated
FALSEevaluated 48 times by 1 test
Evaluated by:
  • Self test
*++pat == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 47 times by 1 test
Evaluated by:
  • Self test
*pat == 0Description
TRUEnever evaluated
FALSEnever evaluated
*++pat == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-48
136 {-
137 matlen += bracklen;-
138 goto bad_bracket;
executed 1 time by 1 test: goto bad_bracket;
Executed by:
  • Self test
never executed: goto bad_bracket;
0-1
139 }-
140 }
executed 47 times by 1 test: end of block
Executed by:
  • Self test
never executed: end of block
0-47
141 else if (c == L('[') && *pat == L(':')) /* character class */
c == '['Description
TRUEevaluated 17798 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 195801 times by 1 test
Evaluated by:
  • Self test
*pat == ':'Description
TRUEevaluated 17798 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
c == L'['Description
TRUEnever evaluated
FALSEnever evaluated
*pat == L':'Description
TRUEnever evaluated
FALSEnever evaluated
0-195801
142 {-
143 pat++;-
144 bracklen++;-
145 in_cclass = 1;-
146 }
executed 17798 times by 1 test: end of block
Executed by:
  • Self test
never executed: end of block
0-17798
147 else if (in_cclass && c == L(':') && *pat == L(']'))
in_cclassDescription
TRUEevaluated 106785 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 89016 times by 1 test
Evaluated by:
  • Self test
c == ':'Description
TRUEevaluated 17795 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 88990 times by 1 test
Evaluated by:
  • Self test
*pat == ']'Description
TRUEevaluated 17795 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
in_cclassDescription
TRUEnever evaluated
FALSEnever evaluated
c == L':'Description
TRUEnever evaluated
FALSEnever evaluated
*pat == L']'Description
TRUEnever evaluated
FALSEnever evaluated
0-106785
148 {-
149 pat++;-
150 bracklen++;-
151 in_cclass = 0;-
152 }
executed 17795 times by 1 test: end of block
Executed by:
  • Self test
never executed: end of block
0-17795
153 else if (c == L('[') && *pat == L('.')) /* collating symbol */
c == '['Description
TRUEnever evaluated
FALSEevaluated 178006 times by 1 test
Evaluated by:
  • Self test
*pat == '.'Description
TRUEnever evaluated
FALSEnever evaluated
c == L'['Description
TRUEnever evaluated
FALSEnever evaluated
*pat == L'.'Description
TRUEnever evaluated
FALSEnever evaluated
0-178006
154 {-
155 pat++;-
156 bracklen++;-
157 if (*pat == L(']')) /* right bracket can appear as collating symbol */
*pat == ']'Description
TRUEnever evaluated
FALSEnever evaluated
*pat == L']'Description
TRUEnever evaluated
FALSEnever evaluated
0
158 {-
159 pat++;-
160 bracklen++;-
161 }
never executed: end of block
never executed: end of block
0
162 in_collsym = 1;-
163 }
never executed: end of block
never executed: end of block
0
164 else if (in_collsym && c == L('.') && *pat == L(']'))
in_collsymDescription
TRUEnever evaluated
FALSEevaluated 178006 times by 1 test
Evaluated by:
  • Self test
c == '.'Description
TRUEnever evaluated
FALSEnever evaluated
*pat == ']'Description
TRUEnever evaluated
FALSEnever evaluated
in_collsymDescription
TRUEnever evaluated
FALSEnever evaluated
c == L'.'Description
TRUEnever evaluated
FALSEnever evaluated
*pat == L']'Description
TRUEnever evaluated
FALSEnever evaluated
0-178006
165 {-
166 pat++;-
167 bracklen++;-
168 in_collsym = 0;-
169 }
never executed: end of block
never executed: end of block
0
170 else if (c == L('[') && *pat == L('=')) /* equivalence class */
c == '['Description
TRUEnever evaluated
FALSEevaluated 178006 times by 1 test
Evaluated by:
  • Self test
*pat == '='Description
TRUEnever evaluated
FALSEnever evaluated
c == L'['Description
TRUEnever evaluated
FALSEnever evaluated
*pat == L'='Description
TRUEnever evaluated
FALSEnever evaluated
0-178006
171 {-
172 pat++;-
173 bracklen++;-
174 if (*pat == L(']')) /* right bracket can appear as equivalence class */
*pat == ']'Description
TRUEnever evaluated
FALSEnever evaluated
*pat == L']'Description
TRUEnever evaluated
FALSEnever evaluated
0
175 {-
176 pat++;-
177 bracklen++;-
178 }
never executed: end of block
never executed: end of block
0
179 in_equiv = 1;-
180 }
never executed: end of block
never executed: end of block
0
181 else if (in_equiv && c == L('=') && *pat == L(']'))
in_equivDescription
TRUEnever evaluated
FALSEevaluated 178006 times by 1 test
Evaluated by:
  • Self test
c == '='Description
TRUEnever evaluated
FALSEnever evaluated
*pat == ']'Description
TRUEnever evaluated
FALSEnever evaluated
in_equivDescription
TRUEnever evaluated
FALSEnever evaluated
c == L'='Description
TRUEnever evaluated
FALSEnever evaluated
*pat == L']'Description
TRUEnever evaluated
FALSEnever evaluated
0-178006
182 {-
183 pat++;-
184 bracklen++;-
185 in_equiv = 0;-
186 }
never executed: end of block
never executed: end of block
0
187 else-
188 bracklen++;
executed 178006 times by 1 test: bracklen++;
Executed by:
  • Self test
never executed: bracklen++;
0-178006
189 }-
190 while ((c = *pat++) != L(']'));
(c = *pat++) != ']'Description
TRUEevaluated 160198 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 53448 times by 1 test
Evaluated by:
  • Self test
(c = *pat++) != L']'Description
TRUEnever evaluated
FALSEnever evaluated
0-160198
191 matlen++; /* bracket expression can only match one char */-
192bad_bracket:
code before this statement executed 53448 times by 1 test: bad_bracket:
Executed by:
  • Self test
code before this statement never executed: bad_bracket:
0-53448
193 break;
executed 53452 times by 1 test: break;
Executed by:
  • Self test
never executed: break;
0-53452
194 }-
195 }-
196-
197 return matlen;
executed 59064 times by 1 test: return matlen;
Executed by:
  • Self test
executed 7 times by 1 test: return matlen;
Executed by:
  • Self test
7-59064
198}-
199-
200#undef EXTGLOB_PATTERN_P-
201#undef MATCH_PATTERN_CHAR-
202#undef MATCHLEN-
203#undef FOLD-
204#undef L-
205#undef LPAREN-
206#undef RPAREN-
207#undef INT-
208#undef CHAR-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2