OpenCoverage

braces.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/braces.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* braces.c -- code for doing word expansion in curly braces. */-
2-
3/* Copyright (C) 1987-2012 Free Software Foundation, Inc.-
4-
5 This file is part of GNU Bash, the Bourne Again SHell.-
6-
7 Bash is free software: you can redistribute it and/or modify-
8 it under the terms of the GNU General Public License as published by-
9 the Free Software Foundation, either version 3 of the License, or-
10 (at your option) any later version.-
11-
12 Bash is distributed in the hope that it will be useful,-
13 but WITHOUT ANY WARRANTY; without even the implied warranty of-
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
15 GNU General Public License for more details.-
16-
17 You should have received a copy of the GNU General Public License-
18 along with Bash. If not, see <http://www.gnu.org/licenses/>.-
19*/-
20-
21/* Stuff in curly braces gets expanded before all other shell expansions. */-
22-
23#include "config.h"-
24-
25#if defined (BRACE_EXPANSION)-
26-
27#if defined (HAVE_UNISTD_H)-
28# ifdef _MINIX-
29# include <sys/types.h>-
30# endif-
31# include <unistd.h>-
32#endif-
33-
34#include <errno.h>-
35-
36#include "bashansi.h"-
37#include "bashintl.h"-
38-
39#if defined (SHELL)-
40# include "shell.h"-
41#else-
42# if defined (TEST)-
43typedef char *WORD_DESC;-
44typedef char **WORD_LIST;-
45#define _(X) X-
46# endif /* TEST */-
47#endif /* SHELL */-
48-
49#include "typemax.h" /* INTMAX_MIN, INTMAX_MAX */-
50#include "general.h"-
51#include "shmbutil.h"-
52#include "chartypes.h"-
53-
54#ifndef errno-
55extern int errno;-
56#endif-
57-
58#define brace_whitespace(c) (!(c) || (c) == ' ' || (c) == '\t' || (c) == '\n')-
59-
60#define BRACE_SEQ_SPECIFIER ".."-
61-
62extern int asprintf __P((char **, const char *, ...)) __attribute__((__format__ (printf, 2, 3)));-
63-
64#if defined (NOTDEF)-
65extern int last_command_exit_value;-
66#endif-
67-
68/* Basic idea:-
69-
70 Segregate the text into 3 sections: preamble (stuff before an open brace),-
71 postamble (stuff after the matching close brace) and amble (stuff after-
72 preamble, and before postamble). Expand amble, and then tack on the-
73 expansions to preamble. Expand postamble, and tack on the expansions to-
74 the result so far.-
75 */-
76-
77/* The character which is used to separate arguments. */-
78static const int brace_arg_separator = ',';-
79-
80#if defined (__P)-
81static int brace_gobbler __P((char *, size_t, int *, int));-
82static char **expand_amble __P((char *, size_t, int));-
83static char **expand_seqterm __P((char *, size_t));-
84static char **mkseq __P((intmax_t, intmax_t, intmax_t, int, int));-
85static char **array_concat __P((char **, char **));-
86#else-
87static int brace_gobbler ();-
88static char **expand_amble ();-
89static char **expand_seqterm ();-
90static char **mkseq();-
91static char **array_concat ();-
92#endif-
93-
94#if 0-
95static void-
96dump_result (a)-
97 char **a;-
98{-
99 int i;-
100-
101 for (i = 0; a[i]; i++)-
102 printf ("dump_result: a[%d] = -%s-\n", i, a[i]);-
103}-
104#endif-
105-
106/* Return an array of strings; the brace expansion of TEXT. */-
107char **-
108brace_expand (text)-
109 char *text;-
110{-
111 register int start;-
112 size_t tlen;-
113 char *preamble, *postamble, *amble;-
114 size_t alen;-
115 char **tack, **result;-
116 int i, j, c, c1;-
117-
118 DECLARE_MBSTATE;-
119-
120 /* Find the text of the preamble. */-
121 tlen = strlen (text);-
122 i = 0;-
123#if defined (CSH_BRACE_COMPAT)-
124 c = brace_gobbler (text, tlen, &i, '{'); /* } */-
125#else-
126 /* Make sure that when we exit this loop, c == 0 or text[i] begins a-
127 valid brace expansion sequence. */-
128 do-
129 {-
130 c = brace_gobbler (text, tlen, &i, '{'); /* } */-
131 c1 = c;-
132 /* Verify that c begins a valid brace expansion word. If it doesn't, we-
133 go on. Loop stops when there are no more open braces in the word. */-
134 if (c)
cDescription
TRUEevaluated 151 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 39197 times by 1 test
Evaluated by:
  • Self test
151-39197
135 {-
136 start = j = i + 1; /* { */-
137 c = brace_gobbler (text, tlen, &j, '}');-
138 if (c == 0) /* it's not */
c == 0Description
TRUEevaluated 33 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 118 times by 1 test
Evaluated by:
  • Self test
33-118
139 {-
140 i++;-
141 c = c1;-
142 continue;
executed 33 times by 1 test: continue;
Executed by:
  • Self test
33
143 }-
144 else /* it is */-
145 {-
146 c = c1;-
147 break;
executed 118 times by 1 test: break;
Executed by:
  • Self test
118
148 }-
149 }-
150 else-
151 break;
executed 39197 times by 1 test: break;
Executed by:
  • Self test
39197
152 }-
153 while (c);
cDescription
TRUEevaluated 33 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-33
154#endif /* !CSH_BRACE_COMPAT */-
155-
156 preamble = (char *)xmalloc (i + 1);-
157 if (i > 0)
i > 0Description
TRUEevaluated 39244 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 71 times by 1 test
Evaluated by:
  • Self test
71-39244
158 strncpy (preamble, text, i);
executed 39244 times by 1 test: __builtin_strncpy ( preamble , text , i ) ;
Executed by:
  • Self test
39244
159 preamble[i] = '\0';-
160-
161 result = (char **)xmalloc (2 * sizeof (char *));-
162 result[0] = preamble;-
163 result[1] = (char *)NULL;-
164-
165 /* Special case. If we never found an exciting character, then-
166 the preamble is all of the text, so just return that. */-
167 if (c != '{')
c != '{'Description
TRUEevaluated 39197 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 118 times by 1 test
Evaluated by:
  • Self test
118-39197
168 return (result);
executed 39197 times by 1 test: return (result);
Executed by:
  • Self test
39197
169-
170 /* Find the amble. This is the stuff inside this set of braces. */-
171 start = ++i;-
172 c = brace_gobbler (text, tlen, &i, '}');-
173-
174 /* What if there isn't a matching close brace? */-
175 if (c == 0)
c == 0Description
TRUEnever evaluated
FALSEevaluated 118 times by 1 test
Evaluated by:
  • Self test
0-118
176 {-
177#if defined (NOTDEF)-
178 /* Well, if we found an unquoted BRACE_ARG_SEPARATOR between START-
179 and I, then this should be an error. Otherwise, it isn't. */-
180 j = start;-
181 while (j < i)-
182 {-
183 if (text[j] == '\\')-
184 {-
185 j++;-
186 ADVANCE_CHAR (text, tlen, j);-
187 continue;-
188 }-
189-
190 if (text[j] == brace_arg_separator)-
191 { /* { */-
192 strvec_dispose (result);-
193 last_command_exit_value = 1;-
194 report_error ("no closing `%c' in %s", '}', text);-
195 throw_to_top_level ();-
196 }-
197 ADVANCE_CHAR (text, tlen, j);-
198 }-
199#endif-
200 free (preamble); /* Same as result[0]; see initialization. */-
201 result[0] = savestring (text);-
202 return (result);
never executed: return (result);
0
203 }-
204-
205#if defined (SHELL)-
206 amble = substring (text, start, i);-
207 alen = i - start;-
208#else-
209 amble = (char *)xmalloc (1 + (i - start));-
210 strncpy (amble, &text[start], (i - start));-
211 alen = i - start;-
212 amble[alen] = '\0';-
213#endif-
214-
215#if defined (SHELL)-
216 INITIALIZE_MBSTATE;-
217-
218 /* If the amble does not contain an unquoted BRACE_ARG_SEPARATOR, then-
219 just return without doing any expansion. */-
220 j = 0;-
221 while (amble[j])
amble[j]Description
TRUEevaluated 594 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 53 times by 1 test
Evaluated by:
  • Self test
53-594
222 {-
223 if (amble[j] == '\\')
amble[j] == '\\'Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 589 times by 1 test
Evaluated by:
  • Self test
5-589
224 {-
225 j++;-
226 ADVANCE_CHAR (amble, alen, j);
executed 5 times by 1 test: mblength = 1;
Executed by:
  • Self test
never executed: mblength = 1;
never executed: end of block
never executed: end of block
never executed: (j)++;
executed 5 times by 1 test: (j) += mblength;
Executed by:
  • Self test
never executed: (j)++;
locale_mb_cur_max > 1Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
_fDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
mblength == 0Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
locale_utf8localeDescription
TRUEnever evaluated
FALSEnever evaluated
(((amble)[j] & 0x80) == 0)Description
TRUEnever evaluated
FALSEnever evaluated
mblength == (size_t)-2Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
mblength == (size_t)-1Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
0-5
227 continue;
executed 5 times by 1 test: continue;
Executed by:
  • Self test
5
228 }-
229-
230 if (amble[j] == brace_arg_separator)
amble[j] == br..._arg_separatorDescription
TRUEevaluated 65 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 524 times by 1 test
Evaluated by:
  • Self test
65-524
231 break;
executed 65 times by 1 test: break;
Executed by:
  • Self test
65
232-
233 ADVANCE_CHAR (amble, alen, j);
executed 516 times by 1 test: mblength = 1;
Executed by:
  • Self test
never executed: mblength = 1;
never executed: end of block
never executed: end of block
never executed: (j)++;
executed 516 times by 1 test: (j) += mblength;
Executed by:
  • Self test
executed 8 times by 1 test: (j)++;
Executed by:
  • Self test
locale_mb_cur_max > 1Description
TRUEevaluated 516 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
_fDescription
TRUEevaluated 516 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
mblength == 0Description
TRUEnever evaluated
FALSEevaluated 516 times by 1 test
Evaluated by:
  • Self test
locale_utf8localeDescription
TRUEnever evaluated
FALSEnever evaluated
(((amble)[j] & 0x80) == 0)Description
TRUEnever evaluated
FALSEnever evaluated
mblength == (size_t)-2Description
TRUEnever evaluated
FALSEevaluated 516 times by 1 test
Evaluated by:
  • Self test
mblength == (size_t)-1Description
TRUEnever evaluated
FALSEevaluated 516 times by 1 test
Evaluated by:
  • Self test
0-516
234 }
executed 524 times by 1 test: end of block
Executed by:
  • Self test
524
235-
236 if (amble[j] == 0)
amble[j] == 0Description
TRUEevaluated 53 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 65 times by 1 test
Evaluated by:
  • Self test
53-65
237 {-
238 tack = expand_seqterm (amble, alen);-
239 if (tack)
tackDescription
TRUEevaluated 37 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 16 times by 1 test
Evaluated by:
  • Self test
16-37
240 goto add_tack;
executed 37 times by 1 test: goto add_tack;
Executed by:
  • Self test
37
241 else if (text[i + 1])
text[i + 1]Description
TRUEnever evaluated
FALSEevaluated 16 times by 1 test
Evaluated by:
  • Self test
0-16
242 {-
243 /* If the sequence expansion fails (e.g., because the integers-
244 overflow), but there is more in the string, try and process-
245 the rest of the string, which may contain additional brace-
246 expansions. Treat the unexpanded sequence term as a simple-
247 string (including the braces). */-
248 tack = strvec_create (2);-
249 tack[0] = savestring (text+start-1);-
250 tack[0][i-start+2] = '\0';-
251 tack[1] = (char *)0;-
252 goto add_tack;
never executed: goto add_tack;
0
253 }-
254 else-
255 {-
256 free (amble);-
257 free (preamble);-
258 result[0] = savestring (text);-
259 return (result);
executed 16 times by 1 test: return (result);
Executed by:
  • Self test
16
260 }-
261 }-
262#endif /* SHELL */-
263-
264 tack = expand_amble (amble, alen, 0);-
265add_tack:
code before this statement executed 65 times by 1 test: add_tack:
Executed by:
  • Self test
65
266 result = array_concat (result, tack);-
267 free (amble);-
268 if (tack != result)
tack != resultDescription
TRUEevaluated 49 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 53 times by 1 test
Evaluated by:
  • Self test
49-53
269 strvec_dispose (tack);
executed 49 times by 1 test: strvec_dispose (tack);
Executed by:
  • Self test
49
270-
271 postamble = text + i + 1;-
272-
273 if (postamble && *postamble)
postambleDescription
TRUEevaluated 102 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
*postambleDescription
TRUEevaluated 27 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 75 times by 1 test
Evaluated by:
  • Self test
0-102
274 {-
275 tack = brace_expand (postamble);-
276 result = array_concat (result, tack);-
277 if (tack != result)
tack != resultDescription
TRUEevaluated 27 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-27
278 strvec_dispose (tack);
executed 27 times by 1 test: strvec_dispose (tack);
Executed by:
  • Self test
27
279 }
executed 27 times by 1 test: end of block
Executed by:
  • Self test
27
280-
281 return (result);
executed 102 times by 1 test: return (result);
Executed by:
  • Self test
102
282}-
283-
284/* Expand the text found inside of braces. We simply try to split the-
285 text at BRACE_ARG_SEPARATORs into separate strings. We then brace-
286 expand each slot which needs it, until there are no more slots which-
287 need it. */-
288static char **-
289expand_amble (text, tlen, flags)-
290 char *text;-
291 size_t tlen;-
292 int flags;-
293{-
294 char **result, **partial, **tresult;-
295 char *tem;-
296 int start, i, c;-
297-
298#if defined (SHELL)-
299 DECLARE_MBSTATE;-
300#endif-
301-
302 result = (char **)NULL;-
303-
304 start = i = 0;-
305 c = 1;-
306 while (c)
cDescription
TRUEevaluated 181 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 65 times by 1 test
Evaluated by:
  • Self test
65-181
307 {-
308 c = brace_gobbler (text, tlen, &i, brace_arg_separator);-
309#if defined (SHELL)-
310 tem = substring (text, start, i);-
311#else-
312 tem = (char *)xmalloc (1 + (i - start));-
313 strncpy (tem, &text[start], (i - start));-
314 tem[i - start] = '\0';-
315#endif-
316-
317 partial = brace_expand (tem);-
318-
319 if (!result)
!resultDescription
TRUEevaluated 65 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 116 times by 1 test
Evaluated by:
  • Self test
65-116
320 result = partial;
executed 65 times by 1 test: result = partial;
Executed by:
  • Self test
65
321 else-
322 {-
323 register int lr, lp, j;-
324-
325 lr = strvec_len (result);-
326 lp = strvec_len (partial);-
327-
328 tresult = strvec_mresize (result, lp + lr + 1);-
329 if (tresult == 0)
tresult == 0Description
TRUEnever evaluated
FALSEevaluated 116 times by 1 test
Evaluated by:
  • Self test
0-116
330 {-
331 internal_error (_("brace expansion: cannot allocate memory for %s"), tem);-
332 free (tem);-
333 strvec_dispose (partial);-
334 strvec_dispose (result);-
335 result = (char **)NULL;-
336 return result;
never executed: return result;
0
337 }-
338 else-
339 result = tresult;
executed 116 times by 1 test: result = tresult;
Executed by:
  • Self test
116
340-
341 for (j = 0; j < lp; j++)
j < lpDescription
TRUEevaluated 122 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 116 times by 1 test
Evaluated by:
  • Self test
116-122
342 result[lr + j] = partial[j];
executed 122 times by 1 test: result[lr + j] = partial[j];
Executed by:
  • Self test
122
343-
344 result[lr + j] = (char *)NULL;-
345 free (partial);-
346 }
executed 116 times by 1 test: end of block
Executed by:
  • Self test
116
347 free (tem);-
348#if defined (SHELL)-
349 ADVANCE_CHAR (text, tlen, i);
executed 97 times by 1 test: mblength = 1;
Executed by:
  • Self test
executed 55 times by 1 test: mblength = 1;
Executed by:
  • Self test
never executed: end of block
never executed: end of block
never executed: (i)++;
executed 152 times by 1 test: (i) += mblength;
Executed by:
  • Self test
executed 29 times by 1 test: (i)++;
Executed by:
  • Self test
locale_mb_cur_max > 1Description
TRUEevaluated 152 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 29 times by 1 test
Evaluated by:
  • Self test
_fDescription
TRUEevaluated 97 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 55 times by 1 test
Evaluated by:
  • Self test
mblength == 0Description
TRUEnever evaluated
FALSEevaluated 152 times by 1 test
Evaluated by:
  • Self test
locale_utf8localeDescription
TRUEevaluated 55 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(((text)[i] & 0x80) == 0)Description
TRUEevaluated 55 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
mblength == (size_t)-2Description
TRUEnever evaluated
FALSEevaluated 152 times by 1 test
Evaluated by:
  • Self test
mblength == (size_t)-1Description
TRUEnever evaluated
FALSEevaluated 152 times by 1 test
Evaluated by:
  • Self test
0-152
350#else-
351 i++;-
352#endif-
353 start = i;-
354 }
executed 181 times by 1 test: end of block
Executed by:
  • Self test
181
355 return (result);
executed 65 times by 1 test: return (result);
Executed by:
  • Self test
65
356}-
357-
358#define ST_BAD 0-
359#define ST_INT 1-
360#define ST_CHAR 2-
361#define ST_ZINT 3-
362-
363#ifndef sh_imaxabs-
364# define sh_imaxabs(x) (((x) >= 0) ? (x) : -(x))-
365#endif-
366-
367/* Handle signed arithmetic overflow and underflow. Have to do it this way-
368 to avoid compilers optimizing out simpler overflow checks. */-
369-
370/* Make sure that a+b does not exceed MAXV or is smaller than MINV (if b < 0).-
371 Assumes that b > 0 if a > 0 and b < 0 if a < 0 */-
372#define ADDOVERFLOW(a,b,minv,maxv) \-
373 ((((a) > 0) && ((b) > ((maxv) - (a)))) || \-
374 (((a) < 0) && ((b) < ((minv) - (a)))))-
375-
376/* Make sure that a-b is not smaller than MINV or exceeds MAXV (if b < 0).-
377 Assumes that b > 0 if a > 0 and b < 0 if a < 0 */-
378#define SUBOVERFLOW(a,b,minv,maxv) \-
379 ((((b) > 0) && ((a) < ((minv) + (b)))) || \-
380 (((b) < 0) && ((a) > ((maxv) + (b)))))-
381-
382static char **-
383mkseq (start, end, incr, type, width)-
384 intmax_t start, end, incr;-
385 int type, width;-
386{-
387 intmax_t n, prevn;-
388 int i, nelem;-
389 char **result, *t;-
390-
391 if (incr == 0)
incr == 0Description
TRUEnever evaluated
FALSEevaluated 37 times by 1 test
Evaluated by:
  • Self test
0-37
392 incr = 1;
never executed: incr = 1;
0
393-
394 if (start > end && incr > 0)
start > endDescription
TRUEevaluated 15 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 22 times by 1 test
Evaluated by:
  • Self test
incr > 0Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
5-22
395 incr = -incr;
executed 10 times by 1 test: incr = -incr;
Executed by:
  • Self test
10
396 else if (start < end && incr < 0)
start < endDescription
TRUEevaluated 19 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
incr < 0Description
TRUEnever evaluated
FALSEevaluated 19 times by 1 test
Evaluated by:
  • Self test
0-19
397 {-
398 if (incr == INTMAX_MIN) /* Don't use -INTMAX_MIN */
incr == (-9223...854775807L -1)Description
TRUEnever evaluated
FALSEnever evaluated
0
399 return ((char **)NULL);
never executed: return ((char **) ((void *)0) );
0
400 incr = -incr;-
401 }
never executed: end of block
0
402-
403 /* Check that end-start will not overflow INTMAX_MIN, INTMAX_MAX. The +3-
404 and -2, not strictly necessary, are there because of the way the number-
405 of elements and value passed to strvec_create() are calculated below. */-
406 if (SUBOVERFLOW (end, start, INTMAX_MIN+3, INTMAX_MAX-2))
((start) > 0)Description
TRUEevaluated 30 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
((end) < (( (-...3) + (start)))Description
TRUEnever evaluated
FALSEevaluated 30 times by 1 test
Evaluated by:
  • Self test
((start) < 0)Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 32 times by 1 test
Evaluated by:
  • Self test
((end) > (( (9...2) + (start)))Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
0-32
407 return ((char **)NULL);
never executed: return ((char **) ((void *)0) );
0
408-
409 prevn = sh_imaxabs (end - start);
((end - start) >= 0)Description
TRUEevaluated 22 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 15 times by 1 test
Evaluated by:
  • Self test
15-22
410 /* Need to check this way in case INT_MAX == INTMAX_MAX */-
411 if (INT_MAX == INTMAX_MAX && (ADDOVERFLOW (prevn, 2, INT_MIN, INT_MAX)))
0x7fffffff == ...036854775807L)Description
TRUEnever evaluated
FALSEevaluated 37 times by 1 test
Evaluated by:
  • Self test
((prevn) > 0)Description
TRUEnever evaluated
FALSEnever evaluated
((2) > ((0x7ff...f) - (prevn)))Description
TRUEnever evaluated
FALSEnever evaluated
((prevn) < 0)Description
TRUEnever evaluated
FALSEnever evaluated
((2) < (( (-0x... ) - (prevn)))Description
TRUEnever evaluated
FALSEnever evaluated
0-37
412 return ((char **)NULL);
never executed: return ((char **) ((void *)0) );
0
413 /* Make sure the assignment to nelem below doesn't end up <= 0 due to-
414 intmax_t overflow */-
415 else if (ADDOVERFLOW ((prevn/sh_imaxabs(incr)), 1, INTMAX_MIN, INTMAX_MAX))
((incr) >= 0)Description
TRUEevaluated 22 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 15 times by 1 test
Evaluated by:
  • Self test
((incr) >= 0)Description
TRUEevaluated 22 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 15 times by 1 test
Evaluated by:
  • Self test
(((prevn/(((in...(incr)))) > 0)Description
TRUEevaluated 33 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
((1) > (( (922...: -(incr))))))Description
TRUEnever evaluated
FALSEevaluated 33 times by 1 test
Evaluated by:
  • Self test
(((prevn/(((in...(incr)))) < 0)Description
TRUEnever evaluated
FALSEevaluated 37 times by 1 test
Evaluated by:
  • Self test
((1) < (( (-92...: -(incr))))))Description
TRUEnever evaluated
FALSEnever evaluated
0-37
416 return ((char **)NULL);
never executed: return ((char **) ((void *)0) );
0
417-
418 /* XXX - TOFIX: potentially allocating a lot of extra memory if-
419 imaxabs(incr) != 1 */-
420 /* Instead of a simple nelem = prevn + 1, something like:-
421 nelem = (prevn / imaxabs(incr)) + 1;-
422 would work */-
423 nelem = (prevn / sh_imaxabs(incr)) + 1;
((incr) >= 0)Description
TRUEevaluated 22 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 15 times by 1 test
Evaluated by:
  • Self test
15-22
424 if (nelem > INT_MAX - 2) /* Don't overflow int */
nelem > 0x7fffffff - 2Description
TRUEnever evaluated
FALSEevaluated 37 times by 1 test
Evaluated by:
  • Self test
0-37
425 return ((char **)NULL);
never executed: return ((char **) ((void *)0) );
0
426 result = strvec_mcreate (nelem + 1);-
427 if (result == 0)
result == 0Description
TRUEnever evaluated
FALSEevaluated 37 times by 1 test
Evaluated by:
  • Self test
0-37
428 {-
429 internal_error (_("brace expansion: failed to allocate memory for %u elements"), (unsigned int)nelem);-
430 return ((char **)NULL);
never executed: return ((char **) ((void *)0) );
0
431 }-
432-
433 /* Make sure we go through the loop at least once, so {3..3} prints `3' */-
434 i = 0;-
435 n = start;-
436 do-
437 {-
438#if defined (SHELL)-
439 if (ISINTERRUPT)
interrupt_state != 0Description
TRUEnever evaluated
FALSEevaluated 10375 times by 1 test
Evaluated by:
  • Self test
0-10375
440 {-
441 strvec_dispose (result);-
442 result = (char **)NULL;-
443 }
never executed: end of block
0
444 QUIT;
never executed: termsig_handler (terminating_signal);
never executed: throw_to_top_level ();
terminating_signalDescription
TRUEnever evaluated
FALSEevaluated 10375 times by 1 test
Evaluated by:
  • Self test
interrupt_stateDescription
TRUEnever evaluated
FALSEevaluated 10375 times by 1 test
Evaluated by:
  • Self test
0-10375
445#endif-
446 if (type == ST_INT)
type == 1Description
TRUEevaluated 10244 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 131 times by 1 test
Evaluated by:
  • Self test
131-10244
447 result[i++] = t = itos (n);
executed 10244 times by 1 test: result[i++] = t = itos (n);
Executed by:
  • Self test
10244
448 else if (type == ST_ZINT)
type == 3Description
TRUEnever evaluated
FALSEevaluated 131 times by 1 test
Evaluated by:
  • Self test
0-131
449 {-
450 int len, arg;-
451 arg = n;-
452 len = asprintf (&t, "%0*d", width, arg);-
453 result[i++] = t;-
454 }
never executed: end of block
0
455 else-
456 {-
457 if (t = (char *)malloc (2))
t = (char *)malloc (2)Description
TRUEevaluated 131 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-131
458 {-
459 t[0] = n;-
460 t[1] = '\0';-
461 }
executed 131 times by 1 test: end of block
Executed by:
  • Self test
131
462 result[i++] = t;-
463 }
executed 131 times by 1 test: end of block
Executed by:
  • Self test
131
464-
465 /* We failed to allocate memory for this number, so we bail. */-
466 if (t == 0)
t == 0Description
TRUEnever evaluated
FALSEevaluated 10375 times by 1 test
Evaluated by:
  • Self test
0-10375
467 {-
468 char *p, lbuf[INT_STRLEN_BOUND(intmax_t) + 1];-
469-
470 /* Easier to do this than mess around with various intmax_t printf-
471 formats (%ld? %lld? %jd?) and PRIdMAX. */-
472 p = inttostr (n, lbuf, sizeof (lbuf));-
473 internal_error (_("brace expansion: failed to allocate memory for `%s'"), p);-
474 strvec_dispose (result);-
475 return ((char **)NULL);
never executed: return ((char **) ((void *)0) );
0
476 }-
477-
478 /* Handle overflow and underflow of n+incr */-
479 if (ADDOVERFLOW (n, incr, INTMAX_MIN, INTMAX_MAX))
((n) > 0)Description
TRUEevaluated 10317 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 58 times by 1 test
Evaluated by:
  • Self test
((incr) > (( (...07L) ) - (n)))Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 10316 times by 1 test
Evaluated by:
  • Self test
((n) < 0)Description
TRUEevaluated 50 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 10324 times by 1 test
Evaluated by:
  • Self test
((incr) < (( (... -1) ) - (n)))Description
TRUEnever evaluated
FALSEevaluated 50 times by 1 test
Evaluated by:
  • Self test
0-10324
480 break;
executed 1 time by 1 test: break;
Executed by:
  • Self test
1
481-
482 n += incr;-
483-
484 if ((incr < 0 && n < end) || (incr > 0 && n > end))
incr < 0Description
TRUEevaluated 166 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 10208 times by 1 test
Evaluated by:
  • Self test
n < endDescription
TRUEevaluated 15 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 151 times by 1 test
Evaluated by:
  • Self test
incr > 0Description
TRUEevaluated 10208 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 151 times by 1 test
Evaluated by:
  • Self test
n > endDescription
TRUEevaluated 21 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 10187 times by 1 test
Evaluated by:
  • Self test
15-10208
485 break;
executed 36 times by 1 test: break;
Executed by:
  • Self test
36
486 }
executed 10338 times by 1 test: end of block
Executed by:
  • Self test
10338
487 while (1);-
488-
489 result[i] = (char *)0;-
490 return (result);
executed 37 times by 1 test: return (result);
Executed by:
  • Self test
37
491}-
492-
493static char **-
494expand_seqterm (text, tlen)-
495 char *text;-
496 size_t tlen;-
497{-
498 char *t, *lhs, *rhs;-
499 int lhs_t, rhs_t, lhs_l, rhs_l, width;-
500 intmax_t lhs_v, rhs_v, incr;-
501 intmax_t tl, tr;-
502 char **result, *ep, *oep;-
503-
504 t = strstr (text, BRACE_SEQ_SPECIFIER);-
505 if (t == 0)
t == 0Description
TRUEnever evaluated
FALSEevaluated 53 times by 1 test
Evaluated by:
  • Self test
0-53
506 return ((char **)NULL);
never executed: return ((char **) ((void *)0) );
0
507-
508 lhs_l = t - text; /* index of start of BRACE_SEQ_SPECIFIER */-
509 lhs = substring (text, 0, lhs_l);-
510 rhs = substring (text, lhs_l + sizeof(BRACE_SEQ_SPECIFIER) - 1, tlen);-
511-
512 if (lhs[0] == 0 || rhs[0] == 0)
lhs[0] == 0Description
TRUEnever evaluated
FALSEevaluated 53 times by 1 test
Evaluated by:
  • Self test
rhs[0] == 0Description
TRUEnever evaluated
FALSEevaluated 53 times by 1 test
Evaluated by:
  • Self test
0-53
513 {-
514 free (lhs);-
515 free (rhs);-
516 return ((char **)NULL);
never executed: return ((char **) ((void *)0) );
0
517 }-
518-
519 /* Now figure out whether LHS and RHS are integers or letters. Both-
520 sides have to match. */-
521 lhs_t = (legal_number (lhs, &tl)) ? ST_INT :
(legal_number (lhs, &tl))Description
TRUEevaluated 43 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 10 times by 1 test
Evaluated by:
  • Self test
10-43
522 ((ISALPHA (lhs[0]) && lhs[1] == 0) ? ST_CHAR : ST_BAD);
((*__ctype_b_l...int) _ISalpha)Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
lhs[1] == 0Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-9
523-
524 /* Decide on rhs and whether or not it looks like the user specified-
525 an increment */-
526 ep = 0;-
527 if (ISDIGIT (rhs[0]) || ((rhs[0] == '+' || rhs[0] == '-') && ISDIGIT (rhs[1])))
((*__ctype_b_l...int) _ISdigit)Description
TRUEevaluated 36 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 17 times by 1 test
Evaluated by:
  • Self test
rhs[0] == '+'Description
TRUEnever evaluated
FALSEevaluated 17 times by 1 test
Evaluated by:
  • Self test
rhs[0] == '-'Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 13 times by 1 test
Evaluated by:
  • Self test
((*__ctype_b_l...int) _ISdigit)Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-36
528 {-
529 rhs_t = ST_INT;-
530 errno = 0;-
531 tr = strtoimax (rhs, &ep, 10);-
532 if (errno == ERANGE || (ep && *ep != 0 && *ep != '.'))
(*__errno_location ()) == 34Description
TRUEnever evaluated
FALSEevaluated 40 times by 1 test
Evaluated by:
  • Self test
epDescription
TRUEevaluated 40 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
*ep != 0Description
TRUEevaluated 21 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 19 times by 1 test
Evaluated by:
  • Self test
*ep != '.'Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 18 times by 1 test
Evaluated by:
  • Self test
0-40
533 rhs_t = ST_BAD; /* invalid */
executed 3 times by 1 test: rhs_t = 0;
Executed by:
  • Self test
3
534 }
executed 40 times by 1 test: end of block
Executed by:
  • Self test
40
535 else if (ISALPHA (rhs[0]) && (rhs[1] == 0 || rhs[1] == '.'))
((*__ctype_b_l...int) _ISalpha)Description
TRUEevaluated 13 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
rhs[1] == 0Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
rhs[1] == '.'Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
0-13
536 {-
537 rhs_t = ST_CHAR;-
538 ep = rhs + 1;-
539 }
executed 10 times by 1 test: end of block
Executed by:
  • Self test
10
540 else-
541 {-
542 rhs_t = ST_BAD;-
543 ep = 0;-
544 }
executed 3 times by 1 test: end of block
Executed by:
  • Self test
3
545-
546 incr = 1;-
547 if (rhs_t != ST_BAD)
rhs_t != 0Description
TRUEevaluated 47 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
6-47
548 {-
549 oep = ep;-
550 errno = 0;-
551 if (ep && *ep == '.' && ep[1] == '.' && ep[2])
epDescription
TRUEevaluated 47 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
*ep == '.'Description
TRUEevaluated 20 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 27 times by 1 test
Evaluated by:
  • Self test
ep[1] == '.'Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
ep[2]Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-47
552 incr = strtoimax (ep + 2, &ep, 10);
executed 17 times by 1 test: incr = strtoimax (ep + 2, &ep, 10);
Executed by:
  • Self test
17
553 if (*ep != 0 || errno == ERANGE)
*ep != 0Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 41 times by 1 test
Evaluated by:
  • Self test
(*__errno_location ()) == 34Description
TRUEnever evaluated
FALSEevaluated 41 times by 1 test
Evaluated by:
  • Self test
0-41
554 rhs_t = ST_BAD; /* invalid incr or overflow */
executed 6 times by 1 test: rhs_t = 0;
Executed by:
  • Self test
6
555 tlen -= ep - oep;-
556 }
executed 47 times by 1 test: end of block
Executed by:
  • Self test
47
557-
558 if (lhs_t != rhs_t || lhs_t == ST_BAD || rhs_t == ST_BAD)
lhs_t != rhs_tDescription
TRUEevaluated 16 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 37 times by 1 test
Evaluated by:
  • Self test
lhs_t == 0Description
TRUEnever evaluated
FALSEevaluated 37 times by 1 test
Evaluated by:
  • Self test
rhs_t == 0Description
TRUEnever evaluated
FALSEevaluated 37 times by 1 test
Evaluated by:
  • Self test
0-37
559 {-
560 free (lhs);-
561 free (rhs);-
562 return ((char **)NULL);
executed 16 times by 1 test: return ((char **) ((void *)0) );
Executed by:
  • Self test
16
563 }-
564-
565 /* OK, we have something. It's either a sequence of integers, ascending-
566 or descending, or a sequence or letters, ditto. Generate the sequence,-
567 put it into a string vector, and return it. */-
568 -
569 if (lhs_t == ST_CHAR)
lhs_t == 2Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 29 times by 1 test
Evaluated by:
  • Self test
8-29
570 {-
571 lhs_v = (unsigned char)lhs[0];-
572 rhs_v = (unsigned char)rhs[0];-
573 width = 1;-
574 }
executed 8 times by 1 test: end of block
Executed by:
  • Self test
8
575 else-
576 {-
577 lhs_v = tl; /* integer truncation */-
578 rhs_v = tr;-
579-
580 /* Decide whether or not the terms need zero-padding */-
581 rhs_l = tlen - lhs_l - sizeof (BRACE_SEQ_SPECIFIER) + 1;-
582 width = 0;-
583 if (lhs_l > 1 && lhs[0] == '0')
lhs_l > 1Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 12 times by 1 test
Evaluated by:
  • Self test
lhs[0] == '0'Description
TRUEnever evaluated
FALSEevaluated 17 times by 1 test
Evaluated by:
  • Self test
0-17
584 width = lhs_l, lhs_t = ST_ZINT;
never executed: width = lhs_l, lhs_t = 3;
0
585 if (lhs_l > 2 && lhs[0] == '-' && lhs[1] == '0')
lhs_l > 2Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 23 times by 1 test
Evaluated by:
  • Self test
lhs[0] == '-'Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
lhs[1] == '0'Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
0-23
586 width = lhs_l, lhs_t = ST_ZINT;
never executed: width = lhs_l, lhs_t = 3;
0
587 if (rhs_l > 1 && rhs[0] == '0' && width < rhs_l)
rhs_l > 1Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 13 times by 1 test
Evaluated by:
  • Self test
rhs[0] == '0'Description
TRUEnever evaluated
FALSEevaluated 16 times by 1 test
Evaluated by:
  • Self test
width < rhs_lDescription
TRUEnever evaluated
FALSEnever evaluated
0-16
588 width = rhs_l, lhs_t = ST_ZINT;
never executed: width = rhs_l, lhs_t = 3;
0
589 if (rhs_l > 2 && rhs[0] == '-' && rhs[1] == '0' && width < rhs_l)
rhs_l > 2Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 22 times by 1 test
Evaluated by:
  • Self test
rhs[0] == '-'Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
rhs[1] == '0'Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
width < rhs_lDescription
TRUEnever evaluated
FALSEnever evaluated
0-22
590 width = rhs_l, lhs_t = ST_ZINT;
never executed: width = rhs_l, lhs_t = 3;
0
591-
592 if (width < lhs_l && lhs_t == ST_ZINT)
width < lhs_lDescription
TRUEevaluated 29 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
lhs_t == 3Description
TRUEnever evaluated
FALSEevaluated 29 times by 1 test
Evaluated by:
  • Self test
0-29
593 width = lhs_l;
never executed: width = lhs_l;
0
594 if (width < rhs_l && lhs_t == ST_ZINT)
width < rhs_lDescription
TRUEevaluated 29 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
lhs_t == 3Description
TRUEnever evaluated
FALSEevaluated 29 times by 1 test
Evaluated by:
  • Self test
0-29
595 width = rhs_l;
never executed: width = rhs_l;
0
596 }
executed 29 times by 1 test: end of block
Executed by:
  • Self test
29
597-
598 result = mkseq (lhs_v, rhs_v, incr, lhs_t, width);-
599-
600 free (lhs);-
601 free (rhs);-
602-
603 return (result);
executed 37 times by 1 test: return (result);
Executed by:
  • Self test
37
604}-
605-
606/* Start at INDEX, and skip characters in TEXT. Set INDEX to the-
607 index of the character matching SATISFY. This understands about-
608 quoting. Return the character that caused us to stop searching;-
609 this is either the same as SATISFY, or 0. */-
610/* If SATISFY is `}', we are looking for a brace expression, so we-
611 should enforce the rules that govern valid brace expansions:-
612 1) to count as an arg separator, a comma or `..' has to be outside-
613 an inner set of braces. -
614*/-
615static int-
616brace_gobbler (text, tlen, indx, satisfy)-
617 char *text;-
618 size_t tlen;-
619 int *indx;-
620 int satisfy;-
621{-
622 register int i, c, quoted, level, commas, pass_next;-
623#if defined (SHELL)-
624 int si;-
625 char *t;-
626#endif-
627 DECLARE_MBSTATE;-
628-
629 level = quoted = pass_next = 0;-
630#if defined (CSH_BRACE_COMPAT)-
631 commas = 1;-
632#else-
633 commas = (satisfy == '}') ? 0 : 1;
(satisfy == '}')Description
TRUEevaluated 269 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 39529 times by 1 test
Evaluated by:
  • Self test
269-39529
634#endif-
635-
636 i = *indx;-
637 while (c = text[i])
c = text[i]Description
TRUEevaluated 708171 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 39295 times by 1 test
Evaluated by:
  • Self test
39295-708171
638 {-
639 if (pass_next)
pass_nextDescription
TRUEevaluated 36454 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 671717 times by 1 test
Evaluated by:
  • Self test
36454-671717
640 {-
641 pass_next = 0;-
642#if defined (SHELL)-
643 ADVANCE_CHAR (text, tlen, i);
executed 36036 times by 1 test: mblength = 1;
Executed by:
  • Self test
executed 75 times by 1 test: mblength = 1;
Executed by:
  • Self test
never executed: end of block
never executed: end of block
never executed: (i)++;
executed 36111 times by 1 test: (i) += mblength;
Executed by:
  • Self test
executed 343 times by 1 test: (i)++;
Executed by:
  • Self test
locale_mb_cur_max > 1Description
TRUEevaluated 36111 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 343 times by 1 test
Evaluated by:
  • Self test
_fDescription
TRUEevaluated 36036 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 75 times by 1 test
Evaluated by:
  • Self test
mblength == 0Description
TRUEnever evaluated
FALSEevaluated 36111 times by 1 test
Evaluated by:
  • Self test
locale_utf8localeDescription
TRUEevaluated 75 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(((text)[i] & 0x80) == 0)Description
TRUEevaluated 75 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
mblength == (size_t)-2Description
TRUEnever evaluated
FALSEevaluated 36111 times by 1 test
Evaluated by:
  • Self test
mblength == (size_t)-1Description
TRUEnever evaluated
FALSEevaluated 36111 times by 1 test
Evaluated by:
  • Self test
0-36111
644#else-
645 i++;-
646#endif-
647 continue;
executed 36454 times by 1 test: continue;
Executed by:
  • Self test
36454
648 }-
649-
650 /* A backslash escapes the next character. This allows backslash to-
651 escape the quote character in a double-quoted string. */-
652 if (c == '\\' && (quoted == 0 || quoted == '"' || quoted == '`'))
c == '\\'Description
TRUEevaluated 1337 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 670380 times by 1 test
Evaluated by:
  • Self test
quoted == 0Description
TRUEevaluated 396 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 941 times by 1 test
Evaluated by:
  • Self test
quoted == '"'Description
TRUEevaluated 867 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 74 times by 1 test
Evaluated by:
  • Self test
quoted == '`'Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 66 times by 1 test
Evaluated by:
  • Self test
8-670380
653 {-
654 pass_next = 1;-
655 i++;-
656 continue;
executed 1271 times by 1 test: continue;
Executed by:
  • Self test
1271
657 }-
658-
659#if defined (SHELL)-
660 /* If compiling for the shell, treat ${...} like \{...} */-
661 if (c == '$' && text[i+1] == '{' && quoted != '\'') /* } */
c == '$'Description
TRUEevaluated 59700 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 610746 times by 1 test
Evaluated by:
  • Self test
text[i+1] == '{'Description
TRUEevaluated 44796 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 14904 times by 1 test
Evaluated by:
  • Self test
quoted != '\''Description
TRUEevaluated 35183 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 9613 times by 1 test
Evaluated by:
  • Self test
9613-610746
662 {-
663 pass_next = 1;-
664 i++;-
665 if (quoted == 0)
quoted == 0Description
TRUEevaluated 12140 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 23043 times by 1 test
Evaluated by:
  • Self test
12140-23043
666 level++;
executed 12140 times by 1 test: level++;
Executed by:
  • Self test
12140
667 continue;
executed 35183 times by 1 test: continue;
Executed by:
  • Self test
35183
668 }-
669#endif-
670-
671 if (quoted)
quotedDescription
TRUEevaluated 513331 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 121932 times by 1 test
Evaluated by:
  • Self test
121932-513331
672 {-
673 if (c == quoted)
c == quotedDescription
TRUEevaluated 34749 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 478582 times by 1 test
Evaluated by:
  • Self test
34749-478582
674 quoted = 0;
executed 34749 times by 1 test: quoted = 0;
Executed by:
  • Self test
34749
675#if defined (SHELL)-
676 /* The shell allows quoted command substitutions */-
677 if (quoted == '"' && c == '$' && text[i+1] == '(') /*)*/
quoted == '"'Description
TRUEevaluated 243185 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 270146 times by 1 test
Evaluated by:
  • Self test
c == '$'Description
TRUEevaluated 6553 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 236632 times by 1 test
Evaluated by:
  • Self test
text[i+1] == '('Description
TRUEevaluated 95 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6458 times by 1 test
Evaluated by:
  • Self test
95-270146
678 goto comsub;
executed 95 times by 1 test: goto comsub;
Executed by:
  • Self test
95
679#endif-
680#if defined (SHELL)-
681 ADVANCE_CHAR (text, tlen, i);
executed 483994 times by 1 test: mblength = 1;
Executed by:
  • Self test
executed 27685 times by 1 test: mblength = 1;
Executed by:
  • Self test
never executed: end of block
never executed: end of block
never executed: (i)++;
executed 511679 times by 1 test: (i) += mblength;
Executed by:
  • Self test
executed 1557 times by 1 test: (i)++;
Executed by:
  • Self test
locale_mb_cur_max > 1Description
TRUEevaluated 511679 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1557 times by 1 test
Evaluated by:
  • Self test
_fDescription
TRUEevaluated 483994 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 27685 times by 1 test
Evaluated by:
  • Self test
mblength == 0Description
TRUEnever evaluated
FALSEevaluated 511679 times by 1 test
Evaluated by:
  • Self test
locale_utf8localeDescription
TRUEevaluated 27685 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(((text)[i] & 0x80) == 0)Description
TRUEevaluated 27685 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
mblength == (size_t)-2Description
TRUEnever evaluated
FALSEevaluated 511679 times by 1 test
Evaluated by:
  • Self test
mblength == (size_t)-1Description
TRUEnever evaluated
FALSEevaluated 511679 times by 1 test
Evaluated by:
  • Self test
0-511679
682#else-
683 i++;-
684#endif-
685 continue;
executed 513236 times by 1 test: continue;
Executed by:
  • Self test
513236
686 }-
687-
688 if (c == '"' || c == '\'' || c == '`')
c == '"'Description
TRUEevaluated 24854 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 97078 times by 1 test
Evaluated by:
  • Self test
c == '\''Description
TRUEevaluated 9849 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 87229 times by 1 test
Evaluated by:
  • Self test
c == '`'Description
TRUEevaluated 78 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 87151 times by 1 test
Evaluated by:
  • Self test
78-97078
689 {-
690 quoted = c;-
691 i++;-
692 continue;
executed 34781 times by 1 test: continue;
Executed by:
  • Self test
34781
693 }-
694-
695#if defined (SHELL)-
696 /* Pass new-style command and process substitutions through unchanged. */-
697 if ((c == '$' || c == '<' || c == '>') && text[i+1] == '(') /* ) */
c == '$'Description
TRUEevaluated 2244 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 84907 times by 1 test
Evaluated by:
  • Self test
c == '<'Description
TRUEevaluated 1890 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 83017 times by 1 test
Evaluated by:
  • Self test
c == '>'Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 83016 times by 1 test
Evaluated by:
  • Self test
text[i+1] == '('Description
TRUEevaluated 64 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4071 times by 1 test
Evaluated by:
  • Self test
1-84907
698 {-
699comsub:-
700 si = i + 2;-
701 t = extract_command_subst (text, &si, 0);-
702 i = si;-
703 free (t);-
704 i++;-
705 continue;
executed 159 times by 1 test: continue;
Executed by:
  • Self test
159
706 }-
707#endif-
708-
709 if (c == satisfy && level == 0 && quoted == 0 && commas > 0)
c == satisfyDescription
TRUEevaluated 592 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 86495 times by 1 test
Evaluated by:
  • Self test
level == 0Description
TRUEevaluated 535 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 57 times by 1 test
Evaluated by:
  • Self test
quoted == 0Description
TRUEevaluated 535 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
commas > 0Description
TRUEevaluated 506 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 29 times by 1 test
Evaluated by:
  • Self test
0-86495
710 {-
711 /* We ignore an open brace surrounded by whitespace, and also-
712 an open brace followed immediately by a close brace preceded-
713 by whitespace. */-
714 if (c == '{' &&
c == '{'Description
TRUEevaluated 154 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 352 times by 1 test
Evaluated by:
  • Self test
154-352
715 ((!i || brace_whitespace (text[i - 1])) &&
!iDescription
TRUEevaluated 84 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 70 times by 1 test
Evaluated by:
  • Self test
!(text[i - 1])Description
TRUEnever evaluated
FALSEevaluated 70 times by 1 test
Evaluated by:
  • Self test
(text[i - 1]) == ' 'Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 69 times by 1 test
Evaluated by:
  • Self test
(text[i - 1]) == '\t'Description
TRUEnever evaluated
FALSEevaluated 69 times by 1 test
Evaluated by:
  • Self test
(text[i - 1]) == '\n'Description
TRUEnever evaluated
FALSEevaluated 69 times by 1 test
Evaluated by:
  • Self test
0-84
716 (brace_whitespace (text[i + 1]) || text[i + 1] == '}')))
!(text[i + 1])Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 83 times by 1 test
Evaluated by:
  • Self test
(text[i + 1]) == ' 'Description
TRUEnever evaluated
FALSEevaluated 83 times by 1 test
Evaluated by:
  • Self test
(text[i + 1]) == '\t'Description
TRUEnever evaluated
FALSEevaluated 83 times by 1 test
Evaluated by:
  • Self test
(text[i + 1]) == '\n'Description
TRUEnever evaluated
FALSEevaluated 83 times by 1 test
Evaluated by:
  • Self test
text[i + 1] == '}'Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 82 times by 1 test
Evaluated by:
  • Self test
0-83
717 {-
718 i++;-
719 continue;
executed 3 times by 1 test: continue;
Executed by:
  • Self test
3
720 }-
721-
722 break;
executed 503 times by 1 test: break;
Executed by:
  • Self test
503
723 }-
724-
725 if (c == '{')
c == '{'Description
TRUEevaluated 53 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 86528 times by 1 test
Evaluated by:
  • Self test
53-86528
726 level++;
executed 53 times by 1 test: level++;
Executed by:
  • Self test
53
727 else if (c == '}' && level)
c == '}'Description
TRUEevaluated 12296 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 74232 times by 1 test
Evaluated by:
  • Self test
levelDescription
TRUEevaluated 12186 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 110 times by 1 test
Evaluated by:
  • Self test
110-74232
728 level--;
executed 12186 times by 1 test: level--;
Executed by:
  • Self test
12186
729#if !defined (CSH_BRACE_COMPAT)-
730 else if (satisfy == '}' && c == brace_arg_separator && level == 0)
satisfy == '}'Description
TRUEevaluated 2132 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 72210 times by 1 test
Evaluated by:
  • Self test
c == brace_arg_separatorDescription
TRUEevaluated 258 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1874 times by 1 test
Evaluated by:
  • Self test
level == 0Description
TRUEevaluated 232 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 26 times by 1 test
Evaluated by:
  • Self test
26-72210
731 commas++;
executed 232 times by 1 test: commas++;
Executed by:
  • Self test
232
732 else if (satisfy == '}' && STREQN (text+i, BRACE_SEQ_SPECIFIER, 2) &&
never executed: __result = (((const unsigned char *) (const char *) ( text+i ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( ".." ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
(2 == 0)Description
TRUEnever evaluated
FALSEevaluated 1900 times by 1 test
Evaluated by:
  • Self test
satisfy == '}'Description
TRUEevaluated 1900 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 72210 times by 1 test
Evaluated by:
  • Self test
((2 == 0) ? (1..., 2 ))) == 0))Description
TRUEevaluated 150 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1750 times by 1 test
Evaluated by:
  • Self test
(text+i)[0] == ("..")[0]Description
TRUEevaluated 310 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1590 times by 1 test
Evaluated by:
  • Self test
(__extension__..." , 2 ))) == 0Description
TRUEevaluated 150 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 160 times by 1 test
Evaluated by:
  • Self test
__builtin_constant_p ( 2 )Description
TRUEevaluated 310 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
__builtin_cons...t_p ( text+i )Description
TRUEnever evaluated
FALSEevaluated 310 times by 1 test
Evaluated by:
  • Self test
strlen ( text+...size_t) ( 2 ))Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_constant_p ( ".." )Description
TRUEevaluated 310 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
strlen ( ".." ...size_t) ( 2 ))Description
TRUEnever evaluated
FALSEevaluated 310 times by 1 test
Evaluated by:
  • Self test
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-72210
733 text[i+2] != satisfy && level == 0)
text[i+2] != satisfyDescription
TRUEevaluated 150 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
level == 0Description
TRUEevaluated 146 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
0-150
734 commas++;
executed 146 times by 1 test: commas++;
Executed by:
  • Self test
146
735#endif-
736-
737#if defined (SHELL)-
738 ADVANCE_CHAR (text, tlen, i);
executed 78687 times by 1 test: mblength = 1;
Executed by:
  • Self test
executed 3813 times by 1 test: mblength = 1;
Executed by:
  • Self test
never executed: end of block
never executed: end of block
never executed: (i)++;
executed 82500 times by 1 test: (i) += mblength;
Executed by:
  • Self test
executed 4081 times by 1 test: (i)++;
Executed by:
  • Self test
locale_mb_cur_max > 1Description
TRUEevaluated 82500 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4081 times by 1 test
Evaluated by:
  • Self test
_fDescription
TRUEevaluated 78687 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3813 times by 1 test
Evaluated by:
  • Self test
mblength == 0Description
TRUEnever evaluated
FALSEevaluated 82500 times by 1 test
Evaluated by:
  • Self test
locale_utf8localeDescription
TRUEevaluated 3813 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(((text)[i] & 0x80) == 0)Description
TRUEevaluated 3813 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
mblength == (size_t)-2Description
TRUEnever evaluated
FALSEevaluated 82500 times by 1 test
Evaluated by:
  • Self test
mblength == (size_t)-1Description
TRUEnever evaluated
FALSEevaluated 82500 times by 1 test
Evaluated by:
  • Self test
0-82500
739#else-
740 i++;-
741#endif-
742 }
executed 86581 times by 1 test: end of block
Executed by:
  • Self test
86581
743-
744 *indx = i;-
745 return (c);
executed 39798 times by 1 test: return (c);
Executed by:
  • Self test
39798
746}-
747-
748/* Return a new array of strings which is the result of appending each-
749 string in ARR2 to each string in ARR1. The resultant array is-
750 len (arr1) * len (arr2) long. For convenience, ARR1 (and its contents)-
751 are free ()'ed. ARR1 can be NULL, in that case, a new version of ARR2-
752 is returned. */-
753static char **-
754array_concat (arr1, arr2)-
755 char **arr1, **arr2;-
756{-
757 register int i, j, len, len1, len2;-
758 register char **result;-
759-
760 if (arr1 == 0)
arr1 == 0Description
TRUEnever evaluated
FALSEevaluated 129 times by 1 test
Evaluated by:
  • Self test
0-129
761 return (arr2); /* XXX - see if we can get away without copying? */
never executed: return (arr2);
0
762-
763 if (arr2 == 0)
arr2 == 0Description
TRUEnever evaluated
FALSEevaluated 129 times by 1 test
Evaluated by:
  • Self test
0-129
764 return (arr1); /* XXX - caller expects us to free arr1 */
never executed: return (arr1);
0
765-
766 /* We can only short-circuit if the array consists of a single null element;-
767 otherwise we need to replicate the contents of the other array and-
768 prefix (or append, below) an empty element to each one. */-
769 if (arr1[0] && arr1[0][0] == 0 && arr1[1] == 0)
arr1[0]Description
TRUEevaluated 129 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
arr1[0][0] == 0Description
TRUEevaluated 53 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 76 times by 1 test
Evaluated by:
  • Self test
arr1[1] == 0Description
TRUEevaluated 53 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-129
770 {-
771 strvec_dispose (arr1);-
772 return (arr2); /* XXX - use flags to see if we can avoid copying here */
executed 53 times by 1 test: return (arr2);
Executed by:
  • Self test
53
773 }-
774-
775 if (arr2[0] && arr2[0][0] == 0 && arr2[1] == 0)
arr2[0]Description
TRUEevaluated 76 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
arr2[0][0] == 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 74 times by 1 test
Evaluated by:
  • Self test
arr2[1] == 0Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
0-76
776 return (arr1); /* XXX - rather than copying and freeing it */
never executed: return (arr1);
0
777-
778 len1 = strvec_len (arr1);-
779 len2 = strvec_len (arr2);-
780-
781 result = (char **)xmalloc ((1 + (len1 * len2)) * sizeof (char *));-
782-
783 len = 0;-
784 for (i = 0; i < len1; i++)
i < len1Description
TRUEevaluated 166 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 76 times by 1 test
Evaluated by:
  • Self test
76-166
785 {-
786 int strlen_1 = strlen (arr1[i]);-
787-
788 for (j = 0; j < len2; j++)
j < len2Description
TRUEevaluated 293 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 166 times by 1 test
Evaluated by:
  • Self test
166-293
789 {-
790 result[len] = (char *)xmalloc (1 + strlen_1 + strlen (arr2[j]));-
791 strcpy (result[len], arr1[i]);-
792 strcpy (result[len] + strlen_1, arr2[j]);-
793 len++;-
794 }
executed 293 times by 1 test: end of block
Executed by:
  • Self test
293
795 free (arr1[i]);-
796 }
executed 166 times by 1 test: end of block
Executed by:
  • Self test
166
797 free (arr1);-
798-
799 result[len] = (char *)NULL;-
800 return (result);
executed 76 times by 1 test: return (result);
Executed by:
  • Self test
76
801}-
802-
803#if defined (TEST)-
804#include <stdio.h>-
805-
806void *-
807xmalloc(n)-
808 size_t n;-
809{-
810 return (malloc (n));-
811}-
812-
813void *-
814xrealloc(p, n)-
815 void *p;-
816 size_t n;-
817{-
818 return (realloc (p, n));-
819}-
820-
821int-
822internal_error (format, arg1, arg2)-
823 char *format, *arg1, *arg2;-
824{-
825 fprintf (stderr, format, arg1, arg2);-
826 fprintf (stderr, "\n");-
827}-
828 -
829main ()-
830{-
831 char example[256];-
832-
833 for (;;)-
834 {-
835 char **result;-
836 int i;-
837-
838 fprintf (stderr, "brace_expand> ");-
839-
840 if ((!fgets (example, 256, stdin)) ||-
841 (strncmp (example, "quit", 4) == 0))-
842 break;-
843-
844 if (strlen (example))-
845 example[strlen (example) - 1] = '\0';-
846-
847 result = brace_expand (example);-
848-
849 for (i = 0; result[i]; i++)-
850 printf ("%s\n", result[i]);-
851-
852 strvec_dispose (result);-
853 }-
854}-
855 -
856/*-
857 * Local variables:-
858 * compile-command: "gcc -g -Bstatic -DTEST -o brace_expand braces.c general.o"-
859 * end:-
860 */-
861-
862#endif /* TEST */-
863#endif /* BRACE_EXPANSION */-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2