OpenCoverage

subst.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/subst.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* subst.c -- The part of the shell that does parameter, command, arithmetic,-
2 and globbing substitutions. */-
3-
4/* ``Have a little faith, there's magic in the night. You ain't a-
5 beauty, but, hey, you're alright.'' */-
6-
7/* Copyright (C) 1987-2018 Free Software Foundation, Inc.-
8-
9 This file is part of GNU Bash, the Bourne Again SHell.-
10-
11 Bash is free software: you can redistribute it and/or modify-
12 it under the terms of the GNU General Public License as published by-
13 the Free Software Foundation, either version 3 of the License, or-
14 (at your option) any later version.-
15-
16 Bash is distributed in the hope that it will be useful,-
17 but WITHOUT ANY WARRANTY; without even the implied warranty of-
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
19 GNU General Public License for more details.-
20-
21 You should have received a copy of the GNU General Public License-
22 along with Bash. If not, see <http://www.gnu.org/licenses/>.-
23*/-
24-
25#include "config.h"-
26-
27#include "bashtypes.h"-
28#include <stdio.h>-
29#include "chartypes.h"-
30#if defined (HAVE_PWD_H)-
31# include <pwd.h>-
32#endif-
33#include <signal.h>-
34#include <errno.h>-
35-
36#if defined (HAVE_UNISTD_H)-
37# include <unistd.h>-
38#endif-
39-
40#define NEED_FPURGE_DECL-
41-
42#include "bashansi.h"-
43#include "posixstat.h"-
44#include "bashintl.h"-
45-
46#include "shell.h"-
47#include "parser.h"-
48#include "flags.h"-
49#include "jobs.h"-
50#include "execute_cmd.h"-
51#include "filecntl.h"-
52#include "trap.h"-
53#include "pathexp.h"-
54#include "mailcheck.h"-
55-
56#include "shmbutil.h"-
57#if defined (HAVE_MBSTR_H) && defined (HAVE_MBSCHR)-
58# include <mbstr.h> /* mbschr */-
59#endif-
60#include "typemax.h"-
61-
62#include "builtins/getopt.h"-
63#include "builtins/common.h"-
64-
65#include "builtins/builtext.h"-
66-
67#include <tilde/tilde.h>-
68#include <glob/strmatch.h>-
69-
70#if !defined (errno)-
71extern int errno;-
72#endif /* !errno */-
73-
74/* The size that strings change by. */-
75#define DEFAULT_INITIAL_ARRAY_SIZE 112-
76#define DEFAULT_ARRAY_SIZE 128-
77-
78/* Variable types. */-
79#define VT_VARIABLE 0-
80#define VT_POSPARMS 1-
81#define VT_ARRAYVAR 2-
82#define VT_ARRAYMEMBER 3-
83#define VT_ASSOCVAR 4-
84-
85#define VT_STARSUB 128 /* $* or ${array[*]} -- used to split */-
86-
87/* Flags for quoted_strchr */-
88#define ST_BACKSL 0x01-
89#define ST_CTLESC 0x02-
90#define ST_SQUOTE 0x04 /* unused yet */-
91#define ST_DQUOTE 0x08 /* unused yet */-
92-
93/* These defs make it easier to use the editor. */-
94#define LBRACE '{'-
95#define RBRACE '}'-
96#define LPAREN '('-
97#define RPAREN ')'-
98#define LBRACK '['-
99#define RBRACK ']'-
100-
101#if defined (HANDLE_MULTIBYTE)-
102#define WLPAREN L'('-
103#define WRPAREN L')'-
104#endif-
105-
106#define DOLLAR_AT_STAR(c) ((c) == '@' || (c) == '*')-
107#define STR_DOLLAR_AT_STAR(s) (DOLLAR_AT_STAR ((s)[0]) && (s)[1] == '\0')-
108-
109/* Evaluates to 1 if C is one of the shell's special parameters whose length-
110 can be taken, but is also one of the special expansion characters. */-
111#define VALID_SPECIAL_LENGTH_PARAM(c) \-
112 ((c) == '-' || (c) == '?' || (c) == '#' || (c) == '@')-
113-
114/* Evaluates to 1 if C is one of the shell's special parameters for which an-
115 indirect variable reference may be made. */-
116#define VALID_INDIR_PARAM(c) \-
117 ((posixly_correct == 0 && (c) == '#') || (posixly_correct == 0 && (c) == '?') || (c) == '@' || (c) == '*')-
118-
119/* Evaluates to 1 if C is one of the OP characters that follows the parameter-
120 in ${parameter[:]OPword}. */-
121#define VALID_PARAM_EXPAND_CHAR(c) (sh_syntaxtab[(unsigned char)c] & CSUBSTOP)-
122-
123/* Evaluates to 1 if this is one of the shell's special variables. */-
124#define SPECIAL_VAR(name, wi) \-
125 (*name && ((DIGIT (*name) && all_digits (name)) || \-
126 (name[1] == '\0' && (sh_syntaxtab[(unsigned char)*name] & CSPECVAR)) || \-
127 (wi && name[2] == '\0' && VALID_INDIR_PARAM (name[1]))))-
128-
129/* This can be used by all of the *_extract_* functions that have a similar-
130 structure. It can't just be wrapped in a do...while(0) loop because of-
131 the embedded `break'. The dangling else accommodates a trailing semicolon;-
132 we could also put in a do ; while (0) */-
133-
134 -
135#define CHECK_STRING_OVERRUN(oind, ind, len, ch) \-
136 if (ind >= len) \-
137 { \-
138 oind = len; \-
139 ch = 0; \-
140 break; \-
141 } \-
142 else \-
143-
144/* An expansion function that takes a string and a quoted flag and returns-
145 a WORD_LIST *. Used as the type of the third argument to-
146 expand_string_if_necessary(). */-
147typedef WORD_LIST *EXPFUNC __P((char *, int));-
148-
149/* Process ID of the last command executed within command substitution. */-
150pid_t last_command_subst_pid = NO_PID;-
151pid_t current_command_subst_pid = NO_PID;-
152-
153/* Variables used to keep track of the characters in IFS. */-
154SHELL_VAR *ifs_var;-
155char *ifs_value;-
156unsigned char ifs_cmap[UCHAR_MAX + 1];-
157int ifs_is_set, ifs_is_null;-
158-
159#if defined (HANDLE_MULTIBYTE)-
160unsigned char ifs_firstc[MB_LEN_MAX];-
161size_t ifs_firstc_len;-
162#else-
163unsigned char ifs_firstc;-
164#endif-
165-
166/* If non-zero, command substitution inherits the value of errexit option */-
167int inherit_errexit = 0;-
168-
169/* Sentinel to tell when we are performing variable assignments preceding a-
170 command name and putting them into the environment. Used to make sure-
171 we use the temporary environment when looking up variable values. */-
172int assigning_in_environment;-
173-
174/* Used to hold a list of variable assignments preceding a command. Global-
175 so the SIGCHLD handler in jobs.c can unwind-protect it when it runs a-
176 SIGCHLD trap and so it can be saved and restored by the trap handlers. */-
177WORD_LIST *subst_assign_varlist = (WORD_LIST *)NULL;-
178-
179/* Tell the expansion functions to not longjmp back to top_level on fatal-
180 errors. Enabled when doing completion and prompt string expansion. */-
181int no_longjmp_on_fatal_error = 0;-
182-
183/* Non-zero means to allow unmatched globbed filenames to expand to-
184 a null file. */-
185int allow_null_glob_expansion;-
186-
187/* Non-zero means to throw an error when globbing fails to match anything. */-
188int fail_glob_expansion;-
189-
190/* Extern functions and variables from different files. */-
191extern struct fd_bitmap *current_fds_to_close;-
192extern int wordexp_only;-
193-
194#if defined (JOB_CONTROL) && defined (PROCESS_SUBSTITUTION)-
195extern PROCESS *last_procsub_child;-
196#endif-
197-
198#if !defined (HAVE_WCSDUP) && defined (HANDLE_MULTIBYTE)-
199extern wchar_t *wcsdup __P((const wchar_t *));-
200#endif-
201-
202#if 0-
203/* Variables to keep track of which words in an expanded word list (the-
204 output of expand_word_list_internal) are the result of globbing-
205 expansions. GLOB_ARGV_FLAGS is used by execute_cmd.c.-
206 (CURRENTLY UNUSED). */-
207char *glob_argv_flags;-
208static int glob_argv_flags_size;-
209#endif-
210-
211static WORD_LIST *cached_quoted_dollar_at = 0;-
212-
213/* Distinguished error values to return from expansion functions */-
214static WORD_LIST expand_word_error, expand_word_fatal;-
215static WORD_DESC expand_wdesc_error, expand_wdesc_fatal;-
216static char expand_param_error, expand_param_fatal, expand_param_unset;-
217static char extract_string_error, extract_string_fatal;-
218-
219/* Set by expand_word_unsplit and several of the expand_string_XXX functions;-
220 used to inhibit splitting and re-joining $* on $IFS, primarily when doing-
221 assignment statements. The idea is that if we're in a context where this-
222 is set, we're not going to be performing word splitting, so we use the same-
223 rules to expand $* as we would if it appeared within double quotes. */-
224static int expand_no_split_dollar_star = 0;-
225-
226/* A WORD_LIST of words to be expanded by expand_word_list_internal,-
227 without any leading variable assignments. */-
228static WORD_LIST *garglist = (WORD_LIST *)NULL;-
229-
230static char *quoted_substring __P((char *, int, int));-
231static int quoted_strlen __P((char *));-
232static char *quoted_strchr __P((char *, int, int));-
233-
234static char *expand_string_if_necessary __P((char *, int, EXPFUNC *));-
235static inline char *expand_string_to_string_internal __P((char *, int, EXPFUNC *));-
236static WORD_LIST *call_expand_word_internal __P((WORD_DESC *, int, int, int *, int *));-
237static WORD_LIST *expand_string_internal __P((char *, int));-
238static WORD_LIST *expand_string_leave_quoted __P((char *, int));-
239static WORD_LIST *expand_string_for_rhs __P((char *, int, int, int, int *, int *));-
240static WORD_LIST *expand_string_for_pat __P((char *, int, int *, int *));-
241-
242static WORD_LIST *list_quote_escapes __P((WORD_LIST *));-
243static WORD_LIST *list_dequote_escapes __P((WORD_LIST *));-
244-
245static char *make_quoted_char __P((int));-
246static WORD_LIST *quote_list __P((WORD_LIST *));-
247-
248static int unquoted_substring __P((char *, char *));-
249static int unquoted_member __P((int, char *));-
250-
251#if defined (ARRAY_VARS)-
252static SHELL_VAR *do_compound_assignment __P((char *, char *, int));-
253#endif-
254static int do_assignment_internal __P((const WORD_DESC *, int));-
255-
256static char *string_extract_verbatim __P((char *, size_t, int *, char *, int));-
257static char *string_extract __P((char *, int *, char *, int));-
258static char *string_extract_double_quoted __P((char *, int *, int));-
259static inline char *string_extract_single_quoted __P((char *, int *));-
260static inline int skip_single_quoted __P((const char *, size_t, int, int));-
261static int skip_double_quoted __P((char *, size_t, int, int));-
262static char *extract_delimited_string __P((char *, int *, char *, char *, char *, int));-
263static char *extract_dollar_brace_string __P((char *, int *, int, int));-
264static int skip_matched_pair __P((const char *, int, int, int, int));-
265-
266static char *pos_params __P((char *, int, int, int));-
267-
268static unsigned char *mb_getcharlens __P((char *, int));-
269-
270static char *remove_upattern __P((char *, char *, int));-
271#if defined (HANDLE_MULTIBYTE) -
272static wchar_t *remove_wpattern __P((wchar_t *, size_t, wchar_t *, int));-
273#endif-
274static char *remove_pattern __P((char *, char *, int));-
275-
276static int match_upattern __P((char *, char *, int, char **, char **));-
277#if defined (HANDLE_MULTIBYTE)-
278static int match_wpattern __P((wchar_t *, char **, size_t, wchar_t *, int, char **, char **));-
279#endif-
280static int match_pattern __P((char *, char *, int, char **, char **));-
281static int getpatspec __P((int, char *));-
282static char *getpattern __P((char *, int, int));-
283static char *variable_remove_pattern __P((char *, char *, int, int));-
284static char *list_remove_pattern __P((WORD_LIST *, char *, int, int, int));-
285static char *parameter_list_remove_pattern __P((int, char *, int, int));-
286#ifdef ARRAY_VARS-
287static char *array_remove_pattern __P((SHELL_VAR *, char *, int, char *, int));-
288#endif-
289static char *parameter_brace_remove_pattern __P((char *, char *, int, char *, int, int, int));-
290-
291static char *string_var_assignment __P((SHELL_VAR *, char *));-
292#if defined (ARRAY_VARS)-
293static char *array_var_assignment __P((SHELL_VAR *, int, int));-
294#endif-
295static char *pos_params_assignment __P((WORD_LIST *, int, int));-
296static char *string_transform __P((int, SHELL_VAR *, char *));-
297static char *list_transform __P((int, SHELL_VAR *, WORD_LIST *, int, int));-
298static char *parameter_list_transform __P((int, int, int));-
299#if defined ARRAY_VARS-
300static char *array_transform __P((int, SHELL_VAR *, char *, int));-
301#endif-
302static char *parameter_brace_transform __P((char *, char *, int, char *, int, int, int, int));-
303-
304static char *process_substitute __P((char *, int));-
305-
306static char *read_comsub __P((int, int, int, int *));-
307-
308#ifdef ARRAY_VARS-
309static arrayind_t array_length_reference __P((char *));-
310#endif-
311-
312static int valid_brace_expansion_word __P((char *, int));-
313static int chk_atstar __P((char *, int, int *, int *));-
314static int chk_arithsub __P((const char *, int));-
315-
316static WORD_DESC *parameter_brace_expand_word __P((char *, int, int, int, arrayind_t *));-
317static char *parameter_brace_find_indir __P((char *, int, int, int));-
318static WORD_DESC *parameter_brace_expand_indir __P((char *, int, int, int *, int *));-
319static WORD_DESC *parameter_brace_expand_rhs __P((char *, char *, int, int, int, int *, int *));-
320static void parameter_brace_expand_error __P((char *, char *, int));-
321-
322static int valid_length_expression __P((char *));-
323static intmax_t parameter_brace_expand_length __P((char *));-
324-
325static char *skiparith __P((char *, int));-
326static int verify_substring_values __P((SHELL_VAR *, char *, char *, int, intmax_t *, intmax_t *));-
327static int get_var_and_type __P((char *, char *, arrayind_t, int, int, SHELL_VAR **, char **));-
328static char *mb_substring __P((char *, int, int));-
329static char *parameter_brace_substring __P((char *, char *, int, char *, int, int, int));-
330-
331static int shouldexp_replacement __P((char *));-
332-
333static char *pos_params_pat_subst __P((char *, char *, char *, int));-
334-
335static char *parameter_brace_patsub __P((char *, char *, int, char *, int, int, int));-
336-
337static char *pos_params_casemod __P((char *, char *, int, int));-
338static char *parameter_brace_casemod __P((char *, char *, int, int, char *, int, int, int));-
339-
340static WORD_DESC *parameter_brace_expand __P((char *, int *, int, int, int *, int *));-
341static WORD_DESC *param_expand __P((char *, int *, int, int *, int *, int *, int *, int));-
342-
343static WORD_LIST *expand_word_internal __P((WORD_DESC *, int, int, int *, int *));-
344-
345static WORD_LIST *word_list_split __P((WORD_LIST *));-
346-
347static void exp_jump_to_top_level __P((int));-
348-
349static WORD_LIST *separate_out_assignments __P((WORD_LIST *));-
350static WORD_LIST *glob_expand_word_list __P((WORD_LIST *, int));-
351#ifdef BRACE_EXPANSION-
352static WORD_LIST *brace_expand_word_list __P((WORD_LIST *, int));-
353#endif-
354#if defined (ARRAY_VARS)-
355static int make_internal_declare __P((char *, char *, char *));-
356#endif-
357static WORD_LIST *shell_expand_word_list __P((WORD_LIST *, int));-
358static WORD_LIST *expand_word_list_internal __P((WORD_LIST *, int));-
359-
360/* **************************************************************** */-
361/* */-
362/* Utility Functions */-
363/* */-
364/* **************************************************************** */-
365-
366#if defined (DEBUG)-
367void-
368dump_word_flags (flags)-
369 int flags;-
370{-
371 int f;-
372-
373 f = flags;-
374 fprintf (stderr, "%d -> ", f);-
375 if (f & W_ARRAYIND)
f & 0x1000000Description
TRUEnever evaluated
FALSEnever evaluated
0
376 {-
377 f &= ~W_ARRAYIND;-
378 fprintf (stderr, "W_ARRAYIND%s", f ? "|" : "");-
379 }
never executed: end of block
0
380 if (f & W_ASSIGNASSOC)
f & 0x400000Description
TRUEnever evaluated
FALSEnever evaluated
0
381 {-
382 f &= ~W_ASSIGNASSOC;-
383 fprintf (stderr, "W_ASSIGNASSOC%s", f ? "|" : "");-
384 }
never executed: end of block
0
385 if (f & W_ASSIGNARRAY)
f & 0x800000Description
TRUEnever evaluated
FALSEnever evaluated
0
386 {-
387 f &= ~W_ASSIGNARRAY;-
388 fprintf (stderr, "W_ASSIGNARRAY%s", f ? "|" : "");-
389 }
never executed: end of block
0
390 if (f & W_HASCTLESC)
f & 0x200000Description
TRUEnever evaluated
FALSEnever evaluated
0
391 {-
392 f &= ~W_HASCTLESC;-
393 fprintf (stderr, "W_HASCTLESC%s", f ? "|" : "");-
394 }
never executed: end of block
0
395 if (f & W_NOPROCSUB)
f & 0x100000Description
TRUEnever evaluated
FALSEnever evaluated
0
396 {-
397 f &= ~W_NOPROCSUB;-
398 fprintf (stderr, "W_NOPROCSUB%s", f ? "|" : "");-
399 }
never executed: end of block
0
400 if (f & W_DQUOTE)
f & 0x080000Description
TRUEnever evaluated
FALSEnever evaluated
0
401 {-
402 f &= ~W_DQUOTE;-
403 fprintf (stderr, "W_DQUOTE%s", f ? "|" : "");-
404 }
never executed: end of block
0
405 if (f & W_HASQUOTEDNULL)
f & 0x040000Description
TRUEnever evaluated
FALSEnever evaluated
0
406 {-
407 f &= ~W_HASQUOTEDNULL;-
408 fprintf (stderr, "W_HASQUOTEDNULL%s", f ? "|" : "");-
409 }
never executed: end of block
0
410 if (f & W_ASSIGNARG)
f & 0x020000Description
TRUEnever evaluated
FALSEnever evaluated
0
411 {-
412 f &= ~W_ASSIGNARG;-
413 fprintf (stderr, "W_ASSIGNARG%s", f ? "|" : "");-
414 }
never executed: end of block
0
415 if (f & W_ASSNBLTIN)
f & 0x010000Description
TRUEnever evaluated
FALSEnever evaluated
0
416 {-
417 f &= ~W_ASSNBLTIN;-
418 fprintf (stderr, "W_ASSNBLTIN%s", f ? "|" : "");-
419 }
never executed: end of block
0
420 if (f & W_ASSNGLOBAL)
f & 0x2000000Description
TRUEnever evaluated
FALSEnever evaluated
0
421 {-
422 f &= ~W_ASSNGLOBAL;-
423 fprintf (stderr, "W_ASSNGLOBAL%s", f ? "|" : "");-
424 }
never executed: end of block
0
425 if (f & W_COMPASSIGN)
f & 0x008000Description
TRUEnever evaluated
FALSEnever evaluated
0
426 {-
427 f &= ~W_COMPASSIGN;-
428 fprintf (stderr, "W_COMPASSIGN%s", f ? "|" : "");-
429 }
never executed: end of block
0
430 if (f & W_NOEXPAND)
f & 0x004000Description
TRUEnever evaluated
FALSEnever evaluated
0
431 {-
432 f &= ~W_NOEXPAND;-
433 fprintf (stderr, "W_NOEXPAND%s", f ? "|" : "");-
434 }
never executed: end of block
0
435 if (f & W_ITILDE)
f & 0x002000Description
TRUEnever evaluated
FALSEnever evaluated
0
436 {-
437 f &= ~W_ITILDE;-
438 fprintf (stderr, "W_ITILDE%s", f ? "|" : "");-
439 }
never executed: end of block
0
440 if (f & W_NOTILDE)
f & 0x001000Description
TRUEnever evaluated
FALSEnever evaluated
0
441 {-
442 f &= ~W_NOTILDE;-
443 fprintf (stderr, "W_NOTILDE%s", f ? "|" : "");-
444 }
never executed: end of block
0
445 if (f & W_ASSIGNRHS)
f & 0x000800Description
TRUEnever evaluated
FALSEnever evaluated
0
446 {-
447 f &= ~W_ASSIGNRHS;-
448 fprintf (stderr, "W_ASSIGNRHS%s", f ? "|" : "");-
449 }
never executed: end of block
0
450 if (f & W_NOASSNTILDE)
f & 0x20000000Description
TRUEnever evaluated
FALSEnever evaluated
0
451 {-
452 f &= ~W_NOASSNTILDE;-
453 fprintf (stderr, "W_NOASSNTILDE%s", f ? "|" : "");-
454 }
never executed: end of block
0
455 if (f & W_NOCOMSUB)
f & 0x000400Description
TRUEnever evaluated
FALSEnever evaluated
0
456 {-
457 f &= ~W_NOCOMSUB;-
458 fprintf (stderr, "W_NOCOMSUB%s", f ? "|" : "");-
459 }
never executed: end of block
0
460 if (f & W_DOLLARSTAR)
f & 0x000200Description
TRUEnever evaluated
FALSEnever evaluated
0
461 {-
462 f &= ~W_DOLLARSTAR;-
463 fprintf (stderr, "W_DOLLARSTAR%s", f ? "|" : "");-
464 }
never executed: end of block
0
465 if (f & W_DOLLARAT)
f & 0x000100Description
TRUEnever evaluated
FALSEnever evaluated
0
466 {-
467 f &= ~W_DOLLARAT;-
468 fprintf (stderr, "W_DOLLARAT%s", f ? "|" : "");-
469 }
never executed: end of block
0
470 if (f & W_TILDEEXP)
f & 0x000080Description
TRUEnever evaluated
FALSEnever evaluated
0
471 {-
472 f &= ~W_TILDEEXP;-
473 fprintf (stderr, "W_TILDEEXP%s", f ? "|" : "");-
474 }
never executed: end of block
0
475 if (f & W_NOSPLIT2)
f & 0x000040Description
TRUEnever evaluated
FALSEnever evaluated
0
476 {-
477 f &= ~W_NOSPLIT2;-
478 fprintf (stderr, "W_NOSPLIT2%s", f ? "|" : "");-
479 }
never executed: end of block
0
480 if (f & W_NOSPLIT)
f & 0x000010Description
TRUEnever evaluated
FALSEnever evaluated
0
481 {-
482 f &= ~W_NOSPLIT;-
483 fprintf (stderr, "W_NOSPLIT%s", f ? "|" : "");-
484 }
never executed: end of block
0
485 if (f & W_NOBRACE)
f & 0x4000000Description
TRUEnever evaluated
FALSEnever evaluated
0
486 {-
487 f &= ~W_NOBRACE;-
488 fprintf (stderr, "W_NOBRACE%s", f ? "|" : "");-
489 }
never executed: end of block
0
490 if (f & W_NOGLOB)
f & 0x000020Description
TRUEnever evaluated
FALSEnever evaluated
0
491 {-
492 f &= ~W_NOGLOB;-
493 fprintf (stderr, "W_NOGLOB%s", f ? "|" : "");-
494 }
never executed: end of block
0
495 if (f & W_SPLITSPACE)
f & 0x000008Description
TRUEnever evaluated
FALSEnever evaluated
0
496 {-
497 f &= ~W_SPLITSPACE;-
498 fprintf (stderr, "W_SPLITSPACE%s", f ? "|" : "");-
499 }
never executed: end of block
0
500 if (f & W_ASSIGNMENT)
f & 0x000004Description
TRUEnever evaluated
FALSEnever evaluated
0
501 {-
502 f &= ~W_ASSIGNMENT;-
503 fprintf (stderr, "W_ASSIGNMENT%s", f ? "|" : "");-
504 }
never executed: end of block
0
505 if (f & W_QUOTED)
f & 0x000002Description
TRUEnever evaluated
FALSEnever evaluated
0
506 {-
507 f &= ~W_QUOTED;-
508 fprintf (stderr, "W_QUOTED%s", f ? "|" : "");-
509 }
never executed: end of block
0
510 if (f & W_HASDOLLAR)
f & 0x000001Description
TRUEnever evaluated
FALSEnever evaluated
0
511 {-
512 f &= ~W_HASDOLLAR;-
513 fprintf (stderr, "W_HASDOLLAR%s", f ? "|" : "");-
514 }
never executed: end of block
0
515 if (f & W_COMPLETE)
f & 0x8000000Description
TRUEnever evaluated
FALSEnever evaluated
0
516 {-
517 f &= ~W_COMPLETE;-
518 fprintf (stderr, "W_COMPLETE%s", f ? "|" : "");-
519 }
never executed: end of block
0
520 if (f & W_CHKLOCAL)
f & 0x10000000Description
TRUEnever evaluated
FALSEnever evaluated
0
521 {-
522 f &= ~W_CHKLOCAL;-
523 fprintf (stderr, "W_CHKLOCAL%s", f ? "|" : "");-
524 }
never executed: end of block
0
525 -
526 fprintf (stderr, "\n");-
527 fflush (stderr);-
528}
never executed: end of block
0
529#endif-
530-
531#ifdef INCLUDE_UNUSED-
532static char *-
533quoted_substring (string, start, end)-
534 char *string;-
535 int start, end;-
536{-
537 register int len, l;-
538 register char *result, *s, *r;-
539-
540 len = end - start;-
541-
542 /* Move to string[start], skipping quoted characters. */-
543 for (s = string, l = 0; *s && l < start; )-
544 {-
545 if (*s == CTLESC)-
546 {-
547 s++;-
548 continue;-
549 }-
550 l++;-
551 if (*s == 0)-
552 break;-
553 }-
554-
555 r = result = (char *)xmalloc (2*len + 1); /* save room for quotes */-
556-
557 /* Copy LEN characters, including quote characters. */-
558 s = string + l;-
559 for (l = 0; l < len; s++)-
560 {-
561 if (*s == CTLESC)-
562 *r++ = *s++;-
563 *r++ = *s;-
564 l++;-
565 if (*s == 0)-
566 break;-
567 }-
568 *r = '\0';-
569 return result;-
570}-
571#endif-
572-
573#ifdef INCLUDE_UNUSED-
574/* Return the length of S, skipping over quoted characters */-
575static int-
576quoted_strlen (s)-
577 char *s;-
578{-
579 register char *p;-
580 int i;-
581-
582 i = 0;-
583 for (p = s; *p; p++)-
584 {-
585 if (*p == CTLESC)-
586 {-
587 p++;-
588 if (*p == 0)-
589 return (i + 1);-
590 }-
591 i++;-
592 }-
593-
594 return i;-
595}-
596#endif-
597-
598#ifdef INCLUDE_UNUSED-
599/* Find the first occurrence of character C in string S, obeying shell-
600 quoting rules. If (FLAGS & ST_BACKSL) is non-zero, backslash-escaped-
601 characters are skipped. If (FLAGS & ST_CTLESC) is non-zero, characters-
602 escaped with CTLESC are skipped. */-
603static char *-
604quoted_strchr (s, c, flags)-
605 char *s;-
606 int c, flags;-
607{-
608 register char *p;-
609-
610 for (p = s; *p; p++)-
611 {-
612 if (((flags & ST_BACKSL) && *p == '\\')-
613 || ((flags & ST_CTLESC) && *p == CTLESC))-
614 {-
615 p++;-
616 if (*p == '\0')-
617 return ((char *)NULL);-
618 continue;-
619 }-
620 else if (*p == c)-
621 return p;-
622 }-
623 return ((char *)NULL);-
624}-
625-
626/* Return 1 if CHARACTER appears in an unquoted portion of-
627 STRING. Return 0 otherwise. CHARACTER must be a single-byte character. */-
628static int-
629unquoted_member (character, string)-
630 int character;-
631 char *string;-
632{-
633 size_t slen;-
634 int sindex, c;-
635 DECLARE_MBSTATE;-
636-
637 slen = strlen (string);-
638 sindex = 0;-
639 while (c = string[sindex])-
640 {-
641 if (c == character)-
642 return (1);-
643-
644 switch (c)-
645 {-
646 default:-
647 ADVANCE_CHAR (string, slen, sindex);-
648 break;-
649-
650 case '\\':-
651 sindex++;-
652 if (string[sindex])-
653 ADVANCE_CHAR (string, slen, sindex);-
654 break;-
655-
656 case '\'':-
657 sindex = skip_single_quoted (string, slen, ++sindex, 0);-
658 break;-
659-
660 case '"':-
661 sindex = skip_double_quoted (string, slen, ++sindex, 0);-
662 break;-
663 }-
664 }-
665 return (0);-
666}-
667-
668/* Return 1 if SUBSTR appears in an unquoted portion of STRING. */-
669static int-
670unquoted_substring (substr, string)-
671 char *substr, *string;-
672{-
673 size_t slen;-
674 int sindex, c, sublen;-
675 DECLARE_MBSTATE;-
676-
677 if (substr == 0 || *substr == '\0')-
678 return (0);-
679-
680 slen = strlen (string);-
681 sublen = strlen (substr);-
682 for (sindex = 0; c = string[sindex]; )-
683 {-
684 if (STREQN (string + sindex, substr, sublen))-
685 return (1);-
686-
687 switch (c)-
688 {-
689 case '\\':-
690 sindex++;-
691 if (string[sindex])-
692 ADVANCE_CHAR (string, slen, sindex);-
693 break;-
694-
695 case '\'':-
696 sindex = skip_single_quoted (string, slen, ++sindex, 0);-
697 break;-
698-
699 case '"':-
700 sindex = skip_double_quoted (string, slen, ++sindex, 0);-
701 break;-
702-
703 default:-
704 ADVANCE_CHAR (string, slen, sindex);-
705 break;-
706 }-
707 }-
708 return (0);-
709}-
710#endif-
711-
712/* Most of the substitutions must be done in parallel. In order-
713 to avoid using tons of unclear goto's, I have some functions-
714 for manipulating malloc'ed strings. They all take INDX, a-
715 pointer to an integer which is the offset into the string-
716 where manipulation is taking place. They also take SIZE, a-
717 pointer to an integer which is the current length of the-
718 character array for this string. */-
719-
720/* Append SOURCE to TARGET at INDEX. SIZE is the current amount-
721 of space allocated to TARGET. SOURCE can be NULL, in which-
722 case nothing happens. Gets rid of SOURCE by freeing it.-
723 Returns TARGET in case the location has changed. */-
724INLINE char *-
725sub_append_string (source, target, indx, size)-
726 char *source, *target;-
727 int *indx;-
728 size_t *size;-
729{-
730 if (source)
sourceDescription
TRUEevaluated 390464861 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-390464861
731 {-
732 int n;-
733 size_t srclen;-
734-
735 srclen = STRLEN (source);
(source)[1]Description
TRUEevaluated 147985904 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 225929227 times by 1 test
Evaluated by:
  • Self test
(source)[2]Description
TRUEevaluated 81289883 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 66696021 times by 1 test
Evaluated by:
  • Self test
(source)Description
TRUEevaluated 390464861 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(source)[0]Description
TRUEevaluated 373915131 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 16549730 times by 1 test
Evaluated by:
  • Self test
0-390464861
736 if (srclen >= (int)(*size - *indx))
srclen >= (int)(*size - *indx)Description
TRUEevaluated 5186 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 390459675 times by 1 test
Evaluated by:
  • Self test
5186-390459675
737 {-
738 n = srclen + *indx;-
739 n = (n + DEFAULT_ARRAY_SIZE) - (n % DEFAULT_ARRAY_SIZE);-
740 target = (char *)xrealloc (target, (*size = n));-
741 }
executed 5186 times by 1 test: end of block
Executed by:
  • Self test
5186
742-
743 FASTCOPY (source, target + *indx, srclen);-
744 *indx += srclen;-
745 target[*indx] = '\0';-
746-
747 free (source);-
748 }
executed 390464861 times by 1 test: end of block
Executed by:
  • Self test
390464861
749 return (target);
executed 390464861 times by 1 test: return (target);
Executed by:
  • Self test
390464861
750}-
751-
752#if 0-
753/* UNUSED */-
754/* Append the textual representation of NUMBER to TARGET.-
755 INDX and SIZE are as in SUB_APPEND_STRING. */-
756char *-
757sub_append_number (number, target, indx, size)-
758 intmax_t number;-
759 char *target;-
760 int *indx;-
761 size_t *size;-
762{-
763 char *temp;-
764-
765 temp = itos (number);-
766 return (sub_append_string (temp, target, indx, size));-
767}-
768#endif-
769-
770/* Extract a substring from STRING, starting at SINDEX and ending with-
771 one of the characters in CHARLIST. Don't make the ending character-
772 part of the string. Leave SINDEX pointing at the ending character.-
773 Understand about backslashes in the string. If (flags & SX_VARNAME)-
774 is non-zero, and array variables have been compiled into the shell,-
775 everything between a `[' and a corresponding `]' is skipped over.-
776 If (flags & SX_NOALLOC) is non-zero, don't return the substring, just-
777 update SINDEX. If (flags & SX_REQMATCH) is non-zero, the string must-
778 contain a closing character from CHARLIST. */-
779static char *-
780string_extract (string, sindex, charlist, flags)-
781 char *string;-
782 int *sindex;-
783 char *charlist;-
784 int flags;-
785{-
786 register int c, i;-
787 int found;-
788 size_t slen;-
789 char *temp;-
790 DECLARE_MBSTATE;-
791-
792 slen = (MB_CUR_MAX > 1) ? strlen (string + *sindex) + *sindex : 0;
( (__ctype_get...r_max ()) > 1)Description
TRUEevaluated 5600715 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 652 times by 1 test
Evaluated by:
  • Self test
652-5600715
793 i = *sindex;-
794 found = 0;-
795 while (c = string[i])
c = string[i]Description
TRUEevaluated 211573938 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
2-211573938
796 {-
797 if (c == '\\')
c == '\\'Description
TRUEevaluated 358 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 211573580 times by 1 test
Evaluated by:
  • Self test
358-211573580
798 {-
799 if (string[i + 1])
string[i + 1]Description
TRUEevaluated 358 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-358
800 i++;
executed 358 times by 1 test: i++;
Executed by:
  • Self test
358
801 else-
802 break;
never executed: break;
0
803 }-
804#if defined (ARRAY_VARS)-
805 else if ((flags & SX_VARNAME) && c == LBRACK)
(flags & 0x0002)Description
TRUEevaluated 4874176 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 206699404 times by 1 test
Evaluated by:
  • Self test
c == '['Description
TRUEevaluated 6225 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4867951 times by 1 test
Evaluated by:
  • Self test
6225-206699404
806 {-
807 int ni;-
808 /* If this is an array subscript, skip over it and continue. */-
809 ni = skipsubscript (string, i, 0);-
810 if (string[ni] == RBRACK)
string[ni] == ']'Description
TRUEevaluated 6225 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-6225
811 i = ni;
executed 6225 times by 1 test: i = ni;
Executed by:
  • Self test
6225
812 }
executed 6225 times by 1 test: end of block
Executed by:
  • Self test
6225
813#endif-
814 else if (MEMBER (c, charlist))
(c)Description
TRUEevaluated 208335641 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(c)Description
TRUEevaluated 211567355 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
c == (charlist)[0]Description
TRUEevaluated 4389750 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 207177605 times by 1 test
Evaluated by:
  • Self test
!(charlist)[1]Description
TRUEevaluated 3231714 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1158036 times by 1 test
Evaluated by:
  • Self test
(((c) ? ((char...d *)0) ) : 0))Description
TRUEevaluated 2369651 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 205965990 times by 1 test
Evaluated by:
  • Self test
0-211567355
815 {-
816 found = 1;-
817 break;
executed 5601365 times by 1 test: break;
Executed by:
  • Self test
5601365
818 }-
819-
820 ADVANCE_CHAR (string, slen, i);
executed 193047879 times by 1 test: mblength = 1;
Executed by:
  • Self test
executed 12918103 times by 1 test: mblength = 1;
Executed by:
  • Self test
never executed: end of block
never executed: end of block
never executed: (i)++;
executed 205965982 times by 1 test: (i) += mblength;
Executed by:
  • Self test
executed 6591 times by 1 test: (i)++;
Executed by:
  • Self test
locale_mb_cur_max > 1Description
TRUEevaluated 205965982 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6591 times by 1 test
Evaluated by:
  • Self test
_fDescription
TRUEevaluated 193047879 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 12918103 times by 1 test
Evaluated by:
  • Self test
mblength == 0Description
TRUEnever evaluated
FALSEevaluated 205965982 times by 1 test
Evaluated by:
  • Self test
locale_utf8localeDescription
TRUEevaluated 12918103 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(((string)[i] & 0x80) == 0)Description
TRUEevaluated 12918103 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
mblength == (size_t)-2Description
TRUEnever evaluated
FALSEevaluated 205965982 times by 1 test
Evaluated by:
  • Self test
mblength == (size_t)-1Description
TRUEnever evaluated
FALSEevaluated 205965982 times by 1 test
Evaluated by:
  • Self test
0-205965982
821 }
executed 205972573 times by 1 test: end of block
Executed by:
  • Self test
205972573
822-
823 /* If we had to have a matching delimiter and didn't find one, return an-
824 error and let the caller deal with it. */-
825 if ((flags & SX_REQMATCH) && found == 0)
(flags & 0x0004)Description
TRUEevaluated 3231120 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2370247 times by 1 test
Evaluated by:
  • Self test
found == 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3231118 times by 1 test
Evaluated by:
  • Self test
2-3231120
826 {-
827 *sindex = i;-
828 return (&extract_string_error);
executed 2 times by 1 test: return (&extract_string_error);
Executed by:
  • Self test
2
829 }-
830 -
831 temp = (flags & SX_NOALLOC) ? (char *)NULL : substring (string, *sindex, i);
(flags & 0x0001)Description
TRUEevaluated 123 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5601242 times by 1 test
Evaluated by:
  • Self test
123-5601242
832 *sindex = i;-
833 -
834 return (temp);
executed 5601365 times by 1 test: return (temp);
Executed by:
  • Self test
5601365
835}-
836-
837/* Extract the contents of STRING as if it is enclosed in double quotes.-
838 SINDEX, when passed in, is the offset of the character immediately-
839 following the opening double quote; on exit, SINDEX is left pointing after-
840 the closing double quote. If STRIPDQ is non-zero, unquoted double-
841 quotes are stripped and the string is terminated by a null byte.-
842 Backslashes between the embedded double quotes are processed. If STRIPDQ-
843 is zero, an unquoted `"' terminates the string. */-
844static char *-
845string_extract_double_quoted (string, sindex, flags)-
846 char *string;-
847 int *sindex, flags;-
848{-
849 size_t slen;-
850 char *send;-
851 int j, i, t;-
852 unsigned char c;-
853 char *temp, *ret; /* The new string we return. */-
854 int pass_next, backquote, si; /* State variables for the machine. */-
855 int dquote;-
856 int stripdq;-
857 DECLARE_MBSTATE;-
858-
859 slen = strlen (string + *sindex) + *sindex;-
860 send = string + slen;-
861-
862 stripdq = (flags & SX_STRIPDQ);-
863-
864 pass_next = backquote = dquote = 0;-
865 temp = (char *)xmalloc (1 + slen - *sindex);-
866-
867 j = 0;-
868 i = *sindex;-
869 while (c = string[i])
c = string[i]Description
TRUEevaluated 183584657 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2049 times by 1 test
Evaluated by:
  • Self test
2049-183584657
870 {-
871 /* Process a character that was quoted by a backslash. */-
872 if (pass_next)
pass_nextDescription
TRUEevaluated 3018 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 183581639 times by 1 test
Evaluated by:
  • Self test
3018-183581639
873 {-
874 /* XXX - take another look at this in light of Interp 221 */-
875 /* Posix.2 sez:-
876-
877 ``The backslash shall retain its special meaning as an escape-
878 character only when followed by one of the characters:-
879 $ ` " \ <newline>''.-
880-
881 If STRIPDQ is zero, we handle the double quotes here and let-
882 expand_word_internal handle the rest. If STRIPDQ is non-zero,-
883 we have already been through one round of backslash stripping,-
884 and want to strip these backslashes only if DQUOTE is non-zero,-
885 indicating that we are inside an embedded double-quoted string. */-
886-
887 /* If we are in an embedded quoted string, then don't strip-
888 backslashes before characters for which the backslash-
889 retains its special meaning, but remove backslashes in-
890 front of other characters. If we are not in an-
891 embedded quoted string, don't strip backslashes at all.-
892 This mess is necessary because the string was already-
893 surrounded by double quotes (and sh has some really weird-
894 quoting rules).-
895 The returned string will be run through expansion as if-
896 it were double-quoted. */-
897 if ((stripdq == 0 && c != '"') ||
stripdq == 0Description
TRUEevaluated 2942 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 76 times by 1 test
Evaluated by:
  • Self test
c != '"'Description
TRUEevaluated 2361 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 581 times by 1 test
Evaluated by:
  • Self test
76-2942
898 (stripdq && ((dquote && (sh_syntaxtab[c] & CBSDQUOTE)) || dquote == 0)))
stripdqDescription
TRUEevaluated 76 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 581 times by 1 test
Evaluated by:
  • Self test
dquoteDescription
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 69 times by 1 test
Evaluated by:
  • Self test
(sh_syntaxtab[c] & 0x0040)Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
dquote == 0Description
TRUEevaluated 69 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
3-581
899 temp[j++] = '\\';
executed 2433 times by 1 test: temp[j++] = '\\';
Executed by:
  • Self test
2433
900 pass_next = 0;-
901-
902add_one_character:
code before this statement executed 3018 times by 1 test: add_one_character:
Executed by:
  • Self test
3018
903 COPY_CHAR_I (temp, j, string, send, i);
executed 108873915 times by 1 test: mblength = 1;
Executed by:
  • Self test
executed 48187202 times by 1 test: end of block
Executed by:
  • Self test
never executed: end of block
executed 157061117 times by 1 test: mblength = (mblength < 1) ? 1 : mblength;
Executed by:
  • Self test
executed 157061117 times by 1 test: temp[j++] = string[i++];
Executed by:
  • Self test
executed 157061117 times by 1 test: end of block
Executed by:
  • Self test
executed 7431 times by 1 test: temp[j++] = string[i++];
Executed by:
  • Self test
locale_mb_cur_max > 1Description
TRUEevaluated 157061117 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7431 times by 1 test
Evaluated by:
  • Self test
_kDescription
TRUEevaluated 108873915 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 48187202 times by 1 test
Evaluated by:
  • Self test
_k < mblengthDescription
TRUEevaluated 157061117 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 157061117 times by 1 test
Evaluated by:
  • Self test
(mblength < 1)Description
TRUEnever evaluated
FALSEevaluated 157061117 times by 1 test
Evaluated by:
  • Self test
mblength == (size_t)-2Description
TRUEnever evaluated
FALSEevaluated 157061117 times by 1 test
Evaluated by:
  • Self test
mblength == (size_t)-1Description
TRUEnever evaluated
FALSEevaluated 157061117 times by 1 test
Evaluated by:
  • Self test
0-157061117
904 continue;
executed 157068548 times by 1 test: continue;
Executed by:
  • Self test
157068548
905 }-
906-
907 /* A backslash protects the next character. The code just above-
908 handles preserving the backslash in front of any character but-
909 a double quote. */-
910 if (c == '\\')
c == '\\'Description
TRUEevaluated 3018 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 183578621 times by 1 test
Evaluated by:
  • Self test
3018-183578621
911 {-
912 pass_next++;-
913 i++;-
914 continue;
executed 3018 times by 1 test: continue;
Executed by:
  • Self test
3018
915 }-
916-
917 /* Inside backquotes, ``the portion of the quoted string from the-
918 initial backquote and the characters up to the next backquote-
919 that is not preceded by a backslash, having escape characters-
920 removed, defines that command''. */-
921 if (backquote)
backquoteDescription
TRUEevaluated 2151 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 183576470 times by 1 test
Evaluated by:
  • Self test
2151-183576470
922 {-
923 if (c == '`')
c == '`'Description
TRUEevaluated 175 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1976 times by 1 test
Evaluated by:
  • Self test
175-1976
924 backquote = 0;
executed 175 times by 1 test: backquote = 0;
Executed by:
  • Self test
175
925 temp[j++] = c; /* COPY_CHAR_I? */-
926 i++;-
927 continue;
executed 2151 times by 1 test: continue;
Executed by:
  • Self test
2151
928 }-
929-
930 if (c == '`')
c == '`'Description
TRUEevaluated 175 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 183576295 times by 1 test
Evaluated by:
  • Self test
175-183576295
931 {-
932 temp[j++] = c;-
933 backquote++;-
934 i++;-
935 continue;
executed 175 times by 1 test: continue;
Executed by:
  • Self test
175
936 }-
937-
938 /* Pass everything between `$(' and the matching `)' or a quoted-
939 ${ ... } pair through according to the Posix.2 specification. */-
940 if (c == '$' && ((string[i + 1] == LPAREN) || (string[i + 1] == LBRACE)))
c == '$'Description
TRUEevaluated 48219730 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 135356565 times by 1 test
Evaluated by:
  • Self test
(string[i + 1] == '(')Description
TRUEevaluated 5395 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 48214335 times by 1 test
Evaluated by:
  • Self test
(string[i + 1] == '{')Description
TRUEevaluated 30072 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 48184263 times by 1 test
Evaluated by:
  • Self test
5395-135356565
941 {-
942 int free_ret = 1;-
943-
944 si = i + 2;-
945 if (string[i + 1] == LPAREN)
string[i + 1] == '('Description
TRUEevaluated 5395 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 30072 times by 1 test
Evaluated by:
  • Self test
5395-30072
946 ret = extract_command_subst (string, &si, (flags & SX_COMPLETE));
executed 5395 times by 1 test: ret = extract_command_subst (string, &si, (flags & 0x0400));
Executed by:
  • Self test
5395
947 else-
948 ret = extract_dollar_brace_string (string, &si, Q_DOUBLE_QUOTES, 0);
executed 30072 times by 1 test: ret = extract_dollar_brace_string (string, &si, 0x001, 0);
Executed by:
  • Self test
30072
949-
950 temp[j++] = '$';-
951 temp[j++] = string[i + 1];-
952-
953 /* Just paranoia; ret will not be 0 unless no_longjmp_on_fatal_error-
954 is set. */-
955 if (ret == 0 && no_longjmp_on_fatal_error)
ret == 0Description
TRUEnever evaluated
FALSEevaluated 35467 times by 1 test
Evaluated by:
  • Self test
no_longjmp_on_fatal_errorDescription
TRUEnever evaluated
FALSEnever evaluated
0-35467
956 {-
957 free_ret = 0;-
958 ret = string + i + 2;-
959 }
never executed: end of block
0
960-
961 /* XXX - CHECK_STRING_OVERRUN here? */-
962 for (t = 0; ret[t]; t++, j++)
ret[t]Description
TRUEevaluated 398419 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 35467 times by 1 test
Evaluated by:
  • Self test
35467-398419
963 temp[j] = ret[t];
executed 398419 times by 1 test: temp[j] = ret[t];
Executed by:
  • Self test
398419
964 temp[j] = string[si];-
965-
966 if (string[si])
string[si]Description
TRUEevaluated 35467 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-35467
967 {-
968 j++;-
969 i = si + 1;-
970 }
executed 35467 times by 1 test: end of block
Executed by:
  • Self test
35467
971 else-
972 i = si;
never executed: i = si;
0
973-
974 if (free_ret)
free_retDescription
TRUEevaluated 35467 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-35467
975 free (ret);
executed 35467 times by 1 test: sh_xfree((ret), "subst.c", 975);
Executed by:
  • Self test
35467
976 continue;
executed 35467 times by 1 test: continue;
Executed by:
  • Self test
35467
977 }-
978-
979 /* Add any character but a double quote to the quoted string we're-
980 accumulating. */-
981 if (c != '"')
c != '"'Description
TRUEevaluated 157065530 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 26475298 times by 1 test
Evaluated by:
  • Self test
26475298-157065530
982 goto add_one_character;
executed 157065530 times by 1 test: goto add_one_character;
Executed by:
  • Self test
157065530
983-
984 /* c == '"' */-
985 if (stripdq)
stripdqDescription
TRUEevaluated 242 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 26475056 times by 1 test
Evaluated by:
  • Self test
242-26475056
986 {-
987 dquote ^= 1;-
988 i++;-
989 continue;
executed 242 times by 1 test: continue;
Executed by:
  • Self test
242
990 }-
991-
992 break;
executed 26475056 times by 1 test: break;
Executed by:
  • Self test
26475056
993 }-
994 temp[j] = '\0';-
995-
996 /* Point to after the closing quote. */-
997 if (c)
cDescription
TRUEevaluated 26475056 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2049 times by 1 test
Evaluated by:
  • Self test
2049-26475056
998 i++;
executed 26475056 times by 1 test: i++;
Executed by:
  • Self test
26475056
999 *sindex = i;-
1000-
1001 return (temp);
executed 26477105 times by 1 test: return (temp);
Executed by:
  • Self test
26477105
1002}-
1003-
1004/* This should really be another option to string_extract_double_quoted. */-
1005static int-
1006skip_double_quoted (string, slen, sind, flags)-
1007 char *string;-
1008 size_t slen;-
1009 int sind;-
1010 int flags;-
1011{-
1012 int c, i;-
1013 char *ret;-
1014 int pass_next, backquote, si;-
1015 DECLARE_MBSTATE;-
1016-
1017 pass_next = backquote = 0;-
1018 i = sind;-
1019 while (c = string[i])
c = string[i]Description
TRUEevaluated 41887 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-41887
1020 {-
1021 if (pass_next)
pass_nextDescription
TRUEevaluated 71 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 41816 times by 1 test
Evaluated by:
  • Self test
71-41816
1022 {-
1023 pass_next = 0;-
1024 ADVANCE_CHAR (string, slen, i);
executed 60 times by 1 test: mblength = 1;
Executed by:
  • Self test
executed 6 times by 1 test: mblength = 1;
Executed by:
  • Self test
never executed: end of block
never executed: end of block
never executed: (i)++;
executed 66 times by 1 test: (i) += mblength;
Executed by:
  • Self test
executed 5 times by 1 test: (i)++;
Executed by:
  • Self test
locale_mb_cur_max > 1Description
TRUEevaluated 66 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
_fDescription
TRUEevaluated 60 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
mblength == 0Description
TRUEnever evaluated
FALSEevaluated 66 times by 1 test
Evaluated by:
  • Self test
locale_utf8localeDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(((string)[i] & 0x80) == 0)Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
mblength == (size_t)-2Description
TRUEnever evaluated
FALSEevaluated 66 times by 1 test
Evaluated by:
  • Self test
mblength == (size_t)-1Description
TRUEnever evaluated
FALSEevaluated 66 times by 1 test
Evaluated by:
  • Self test
0-66
1025 continue;
executed 71 times by 1 test: continue;
Executed by:
  • Self test
71
1026 }-
1027 else if (c == '\\')
c == '\\'Description
TRUEevaluated 71 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 41745 times by 1 test
Evaluated by:
  • Self test
71-41745
1028 {-
1029 pass_next++;-
1030 i++;-
1031 continue;
executed 71 times by 1 test: continue;
Executed by:
  • Self test
71
1032 }-
1033 else if (backquote)
backquoteDescription
TRUEevaluated 562 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 41183 times by 1 test
Evaluated by:
  • Self test
562-41183
1034 {-
1035 if (c == '`')
c == '`'Description
TRUEevaluated 63 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 499 times by 1 test
Evaluated by:
  • Self test
63-499
1036 backquote = 0;
executed 63 times by 1 test: backquote = 0;
Executed by:
  • Self test
63
1037 ADVANCE_CHAR (string, slen, i);
executed 441 times by 1 test: mblength = 1;
Executed by:
  • Self test
executed 121 times by 1 test: mblength = 1;
Executed by:
  • Self test
never executed: end of block
never executed: end of block
never executed: (i)++;
executed 562 times by 1 test: (i) += mblength;
Executed by:
  • Self test
never executed: (i)++;
locale_mb_cur_max > 1Description
TRUEevaluated 562 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
_fDescription
TRUEevaluated 441 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 121 times by 1 test
Evaluated by:
  • Self test
mblength == 0Description
TRUEnever evaluated
FALSEevaluated 562 times by 1 test
Evaluated by:
  • Self test
locale_utf8localeDescription
TRUEevaluated 121 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(((string)[i] & 0x80) == 0)Description
TRUEevaluated 121 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
mblength == (size_t)-2Description
TRUEnever evaluated
FALSEevaluated 562 times by 1 test
Evaluated by:
  • Self test
mblength == (size_t)-1Description
TRUEnever evaluated
FALSEevaluated 562 times by 1 test
Evaluated by:
  • Self test
0-562
1038 continue;
executed 562 times by 1 test: continue;
Executed by:
  • Self test
562
1039 }-
1040 else if (c == '`')
c == '`'Description
TRUEevaluated 63 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 41120 times by 1 test
Evaluated by:
  • Self test
63-41120
1041 {-
1042 backquote++;-
1043 i++;-
1044 continue;
executed 63 times by 1 test: continue;
Executed by:
  • Self test
63
1045 }-
1046 else if (c == '$' && ((string[i + 1] == LPAREN) || (string[i + 1] == LBRACE)))
c == '$'Description
TRUEevaluated 16265 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 24855 times by 1 test
Evaluated by:
  • Self test
(string[i + 1] == '(')Description
TRUEevaluated 41 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 16224 times by 1 test
Evaluated by:
  • Self test
(string[i + 1] == '{')Description
TRUEevaluated 14137 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2087 times by 1 test
Evaluated by:
  • Self test
41-24855
1047 {-
1048 si = i + 2;-
1049 if (string[i + 1] == LPAREN)
string[i + 1] == '('Description
TRUEevaluated 41 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 14137 times by 1 test
Evaluated by:
  • Self test
41-14137
1050 ret = extract_command_subst (string, &si, SX_NOALLOC|(flags&SX_COMPLETE));
executed 41 times by 1 test: ret = extract_command_subst (string, &si, 0x0001|(flags&0x0400));
Executed by:
  • Self test
41
1051 else-
1052 ret = extract_dollar_brace_string (string, &si, Q_DOUBLE_QUOTES, SX_NOALLOC);
executed 14137 times by 1 test: ret = extract_dollar_brace_string (string, &si, 0x001, 0x0001);
Executed by:
  • Self test
14137
1053-
1054 /* These can consume the entire string if they are unterminated */-
1055 CHECK_STRING_OVERRUN (i, si, slen, c);
never executed: break;
executed 14178 times by 1 test: ;
Executed by:
  • Self test
si >= slenDescription
TRUEnever evaluated
FALSEevaluated 14178 times by 1 test
Evaluated by:
  • Self test
0-14178
1056-
1057 i = si + 1;-
1058 continue;
executed 14178 times by 1 test: continue;
Executed by:
  • Self test
14178
1059 }-
1060 else if (c != '"')
c != '"'Description
TRUEevaluated 9245 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 17697 times by 1 test
Evaluated by:
  • Self test
9245-17697
1061 {-
1062 ADVANCE_CHAR (string, slen, i);
executed 5972 times by 1 test: mblength = 1;
Executed by:
  • Self test
executed 3003 times by 1 test: mblength = 1;
Executed by:
  • Self test
never executed: end of block
never executed: end of block
never executed: (i)++;
executed 8975 times by 1 test: (i) += mblength;
Executed by:
  • Self test
executed 270 times by 1 test: (i)++;
Executed by:
  • Self test
locale_mb_cur_max > 1Description
TRUEevaluated 8975 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 270 times by 1 test
Evaluated by:
  • Self test
_fDescription
TRUEevaluated 5972 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3003 times by 1 test
Evaluated by:
  • Self test
mblength == 0Description
TRUEnever evaluated
FALSEevaluated 8975 times by 1 test
Evaluated by:
  • Self test
locale_utf8localeDescription
TRUEevaluated 3003 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(((string)[i] & 0x80) == 0)Description
TRUEevaluated 3003 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
mblength == (size_t)-2Description
TRUEnever evaluated
FALSEevaluated 8975 times by 1 test
Evaluated by:
  • Self test
mblength == (size_t)-1Description
TRUEnever evaluated
FALSEevaluated 8975 times by 1 test
Evaluated by:
  • Self test
0-8975
1063 continue;
executed 9245 times by 1 test: continue;
Executed by:
  • Self test
9245
1064 }-
1065 else-
1066 break;
executed 17697 times by 1 test: break;
Executed by:
  • Self test
17697
1067 }-
1068-
1069 if (c)
cDescription
TRUEevaluated 17697 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-17697
1070 i++;
executed 17697 times by 1 test: i++;
Executed by:
  • Self test
17697
1071-
1072 return (i);
executed 17698 times by 1 test: return (i);
Executed by:
  • Self test
17698
1073}-
1074-
1075/* Extract the contents of STRING as if it is enclosed in single quotes.-
1076 SINDEX, when passed in, is the offset of the character immediately-
1077 following the opening single quote; on exit, SINDEX is left pointing after-
1078 the closing single quote. */-
1079static inline char *-
1080string_extract_single_quoted (string, sindex)-
1081 char *string;-
1082 int *sindex;-
1083{-
1084 register int i;-
1085 size_t slen;-
1086 char *t;-
1087 DECLARE_MBSTATE;-
1088-
1089 /* Don't need slen for ADVANCE_CHAR unless multibyte chars possible. */-
1090 slen = (MB_CUR_MAX > 1) ? strlen (string + *sindex) + *sindex : 0;
( (__ctype_get...r_max ()) > 1)Description
TRUEevaluated 24824613 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 542 times by 1 test
Evaluated by:
  • Self test
542-24824613
1091 i = *sindex;-
1092 while (string[i] && string[i] != '\'')
string[i]Description
TRUEevaluated 43137340 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
string[i] != '\''Description
TRUEevaluated 18312185 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 24825155 times by 1 test
Evaluated by:
  • Self test
0-43137340
1093 ADVANCE_CHAR (string, slen, i);
executed 18280662 times by 1 test: mblength = 1;
Executed by:
  • Self test
executed 21387 times by 1 test: mblength = 1;
Executed by:
  • Self test
executed 1470 times by 1 test: end of block
Executed by:
  • Self test
executed 233 times by 1 test: end of block
Executed by:
  • Self test
never executed: (i)++;
executed 18303286 times by 1 test: (i) += mblength;
Executed by:
  • Self test
executed 8666 times by 1 test: (i)++;
Executed by:
  • Self test
executed 18312185 times by 1 test: end of block
Executed by:
  • Self test
locale_mb_cur_max > 1Description
TRUEevaluated 18303519 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8666 times by 1 test
Evaluated by:
  • Self test
_fDescription
TRUEevaluated 18280662 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 22857 times by 1 test
Evaluated by:
  • Self test
mblength == 0Description
TRUEnever evaluated
FALSEevaluated 18303286 times by 1 test
Evaluated by:
  • Self test
locale_utf8localeDescription
TRUEevaluated 22857 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(((string)[i] & 0x80) == 0)Description
TRUEevaluated 21387 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1470 times by 1 test
Evaluated by:
  • Self test
mblength == (size_t)-2Description
TRUEnever evaluated
FALSEevaluated 18303519 times by 1 test
Evaluated by:
  • Self test
mblength == (size_t)-1Description
TRUEevaluated 233 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 18303286 times by 1 test
Evaluated by:
  • Self test
0-18312185
1094-
1095 t = substring (string, *sindex, i);-
1096-
1097 if (string[i])
string[i]Description
TRUEevaluated 24825155 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-24825155
1098 i++;
executed 24825155 times by 1 test: i++;
Executed by:
  • Self test
24825155
1099 *sindex = i;-
1100-
1101 return (t);
executed 24825155 times by 1 test: return (t);
Executed by:
  • Self test
24825155
1102}-
1103-
1104/* Skip over a single-quoted string. We overload the SX_COMPLETE flag to mean-
1105 that we are splitting out words for completion and have encountered a $'...'-
1106 string, which allows backslash-escaped single quotes. */-
1107static inline int-
1108skip_single_quoted (string, slen, sind, flags)-
1109 const char *string;-
1110 size_t slen;-
1111 int sind;-
1112 int flags;-
1113{-
1114 register int c;-
1115 DECLARE_MBSTATE;-
1116-
1117 c = sind;-
1118 while (string[c] && string[c] != '\'')
string[c]Description
TRUEevaluated 4633007 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
string[c] != '\''Description
TRUEevaluated 2316883 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2316124 times by 1 test
Evaluated by:
  • Self test
3-4633007
1119 {-
1120 if ((flags & SX_COMPLETE) && string[c] == '\\' && string[c+1] == '\'' && string[c+2])
(flags & 0x0400)Description
TRUEevaluated 37 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2316846 times by 1 test
Evaluated by:
  • Self test
string[c] == '\\'Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 35 times by 1 test
Evaluated by:
  • Self test
string[c+1] == '\''Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
string[c+2]Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-2316846
1121 ADVANCE_CHAR (string, slen, c);
executed 2 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: (c)++;
executed 2 times by 1 test: (c) += mblength;
Executed by:
  • Self test
never executed: (c)++;
executed 2 times by 1 test: end of block
Executed by:
  • Self test
locale_mb_cur_max > 1Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
_fDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
mblength == 0Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
locale_utf8localeDescription
TRUEnever evaluated
FALSEnever evaluated
(((string)[c] & 0x80) == 0)Description
TRUEnever evaluated
FALSEnever evaluated
mblength == (size_t)-2Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
mblength == (size_t)-1Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
0-2
1122 ADVANCE_CHAR (string, slen, c);
executed 2316404 times by 1 test: mblength = 1;
Executed by:
  • Self test
executed 227 times by 1 test: mblength = 1;
Executed by:
  • Self test
never executed: end of block
never executed: end of block
never executed: (c)++;
executed 2316631 times by 1 test: (c) += mblength;
Executed by:
  • Self test
executed 252 times by 1 test: (c)++;
Executed by:
  • Self test
locale_mb_cur_max > 1Description
TRUEevaluated 2316631 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 252 times by 1 test
Evaluated by:
  • Self test
_fDescription
TRUEevaluated 2316404 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 227 times by 1 test
Evaluated by:
  • Self test
mblength == 0Description
TRUEnever evaluated
FALSEevaluated 2316631 times by 1 test
Evaluated by:
  • Self test
locale_utf8localeDescription
TRUEevaluated 227 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(((string)[c] & 0x80) == 0)Description
TRUEevaluated 227 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
mblength == (size_t)-2Description
TRUEnever evaluated
FALSEevaluated 2316631 times by 1 test
Evaluated by:
  • Self test
mblength == (size_t)-1Description
TRUEnever evaluated
FALSEevaluated 2316631 times by 1 test
Evaluated by:
  • Self test
0-2316631
1123 }
executed 2316883 times by 1 test: end of block
Executed by:
  • Self test
2316883
1124-
1125 if (string[c])
string[c]Description
TRUEevaluated 2316124 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
3-2316124
1126 c++;
executed 2316124 times by 1 test: c++;
Executed by:
  • Self test
2316124
1127 return c;
executed 2316127 times by 1 test: return c;
Executed by:
  • Self test
2316127
1128}-
1129-
1130/* Just like string_extract, but doesn't hack backslashes or any of-
1131 that other stuff. Obeys CTLESC quoting. Used to do splitting on $IFS. */-
1132static char *-
1133string_extract_verbatim (string, slen, sindex, charlist, flags)-
1134 char *string;-
1135 size_t slen;-
1136 int *sindex;-
1137 char *charlist;-
1138 int flags;-
1139{-
1140 register int i;-
1141#if defined (HANDLE_MULTIBYTE)-
1142 wchar_t *wcharlist;-
1143#endif-
1144 int c;-
1145 char *temp;-
1146 DECLARE_MBSTATE;-
1147-
1148 if ((flags & SX_NOCTLESC) && charlist[0] == '\'' && charlist[1] == '\0')
(flags & 0x0010)Description
TRUEevaluated 432 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 9374363 times by 1 test
Evaluated by:
  • Self test
charlist[0] == '\''Description
TRUEnever evaluated
FALSEevaluated 432 times by 1 test
Evaluated by:
  • Self test
charlist[1] == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
0-9374363
1149 {-
1150 temp = string_extract_single_quoted (string, sindex);-
1151 --*sindex; /* leave *sindex at separator character */-
1152 return temp;
never executed: return temp;
0
1153 }-
1154-
1155 i = *sindex;-
1156#if defined (HANDLE_MULTIBYTE)-
1157 wcharlist = 0;-
1158#endif-
1159 while (c = string[i])
c = string[i]Description
TRUEevaluated 14322426 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1006095 times by 1 test
Evaluated by:
  • Self test
1006095-14322426
1160 {-
1161#if defined (HANDLE_MULTIBYTE)-
1162 size_t mblength;-
1163#endif-
1164 if ((flags & SX_NOCTLESC) == 0 && c == CTLESC)
(flags & 0x0010) == 0Description
TRUEevaluated 14321051 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1375 times by 1 test
Evaluated by:
  • Self test
c == '\001'Description
TRUEevaluated 103801 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 14217250 times by 1 test
Evaluated by:
  • Self test
1375-14321051
1165 {-
1166 i += 2;-
1167 CHECK_STRING_OVERRUN (i, i, slen, c);
executed 20725 times by 1 test: break;
Executed by:
  • Self test
executed 83076 times by 1 test: ;
Executed by:
  • Self test
i >= slenDescription
TRUEevaluated 20725 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 83076 times by 1 test
Evaluated by:
  • Self test
20725-83076
1168 continue;
executed 83076 times by 1 test: continue;
Executed by:
  • Self test
83076
1169 }-
1170 /* Even if flags contains SX_NOCTLESC, we let CTLESC quoting CTLNUL-
1171 through, to protect the CTLNULs from later calls to-
1172 remove_quoted_nulls. */-
1173 else if ((flags & SX_NOESCCTLNUL) == 0 && c == CTLESC && string[i+1] == CTLNUL)
(flags & 0x0020) == 0Description
TRUEevaluated 14218387 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 238 times by 1 test
Evaluated by:
  • Self test
c == '\001'Description
TRUEevaluated 291 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 14218096 times by 1 test
Evaluated by:
  • Self test
string[i+1] == '\177'Description
TRUEevaluated 34 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 257 times by 1 test
Evaluated by:
  • Self test
34-14218387
1174 {-
1175 i += 2;-
1176 CHECK_STRING_OVERRUN (i, i, slen, c);
never executed: break;
executed 34 times by 1 test: ;
Executed by:
  • Self test
i >= slenDescription
TRUEnever evaluated
FALSEevaluated 34 times by 1 test
Evaluated by:
  • Self test
0-34
1177 continue;
executed 34 times by 1 test: continue;
Executed by:
  • Self test
34
1178 }-
1179-
1180#if defined (HANDLE_MULTIBYTE)-
1181 mblength = MBLEN (string + i, slen - i);
( (__ctype_get...r_max ()) > 1)Description
TRUEevaluated 13795024 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 423567 times by 1 test
Evaluated by:
  • Self test
423567-13795024
1182 if (mblength > 1)
mblength > 1Description
TRUEevaluated 110 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 14218481 times by 1 test
Evaluated by:
  • Self test
110-14218481
1183 {-
1184 wchar_t wc;-
1185 mblength = mbtowc (&wc, string + i, slen - i);-
1186 if (MB_INVALIDCH (mblength))
(mblength) == (size_t)-1Description
TRUEevaluated 40 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 70 times by 1 test
Evaluated by:
  • Self test
(mblength) == (size_t)-2Description
TRUEnever evaluated
FALSEevaluated 70 times by 1 test
Evaluated by:
  • Self test
0-70
1187 {-
1188 if (MEMBER (c, charlist))
(c)Description
TRUEevaluated 40 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(c)Description
TRUEevaluated 40 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
c == (charlist)[0]Description
TRUEnever evaluated
FALSEevaluated 40 times by 1 test
Evaluated by:
  • Self test
!(charlist)[1]Description
TRUEnever evaluated
FALSEnever evaluated
(((c) ? ((char...d *)0) ) : 0))Description
TRUEnever evaluated
FALSEevaluated 40 times by 1 test
Evaluated by:
  • Self test
0-40
1189 break;
never executed: break;
0
1190 }
executed 40 times by 1 test: end of block
Executed by:
  • Self test
40
1191 else-
1192 {-
1193 if (wcharlist == 0)
wcharlist == 0Description
TRUEevaluated 33 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 37 times by 1 test
Evaluated by:
  • Self test
33-37
1194 {-
1195 size_t len;-
1196 len = mbstowcs (wcharlist, charlist, 0);-
1197 if (len == -1)
len == -1Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 30 times by 1 test
Evaluated by:
  • Self test
3-30
1198 len = 0;
executed 3 times by 1 test: len = 0;
Executed by:
  • Self test
3
1199 wcharlist = (wchar_t *)xmalloc (sizeof (wchar_t) * (len + 1));-
1200 mbstowcs (wcharlist, charlist, len + 1);-
1201 }
executed 33 times by 1 test: end of block
Executed by:
  • Self test
33
1202-
1203 if (wcschr (wcharlist, wc))
wcschr (wcharlist, wc)Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 64 times by 1 test
Evaluated by:
  • Self test
6-64
1204 break;
executed 6 times by 1 test: break;
Executed by:
  • Self test
6
1205 }
executed 64 times by 1 test: end of block
Executed by:
  • Self test
64
1206 }-
1207 else -
1208#endif-
1209 if (MEMBER (c, charlist))
(c)Description
TRUEevaluated 14195952 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(c)Description
TRUEevaluated 14218481 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
c == (charlist)[0]Description
TRUEevaluated 4189208 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 10029273 times by 1 test
Evaluated by:
  • Self test
!(charlist)[1]Description
TRUEevaluated 22529 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4166679 times by 1 test
Evaluated by:
  • Self test
(((c) ? ((char...d *)0) ) : 0))Description
TRUEevaluated 8325440 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5870512 times by 1 test
Evaluated by:
  • Self test
0-14218481
1210 break;
executed 8347969 times by 1 test: break;
Executed by:
  • Self test
8347969
1211-
1212 ADVANCE_CHAR (string, slen, i);
executed 5436266 times by 1 test: mblength = 1;
Executed by:
  • Self test
executed 11090 times by 1 test: mblength = 1;
Executed by:
  • Self test
executed 104 times by 1 test: end of block
Executed by:
  • Self test
executed 40 times by 1 test: end of block
Executed by:
  • Self test
never executed: (i)++;
executed 5447420 times by 1 test: (i) += mblength;
Executed by:
  • Self test
executed 423156 times by 1 test: (i)++;
Executed by:
  • Self test
locale_mb_cur_max > 1Description
TRUEevaluated 5447460 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 423156 times by 1 test
Evaluated by:
  • Self test
_fDescription
TRUEevaluated 5436266 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 11194 times by 1 test
Evaluated by:
  • Self test
mblength == 0Description
TRUEnever evaluated
FALSEevaluated 5447420 times by 1 test
Evaluated by:
  • Self test
locale_utf8localeDescription
TRUEevaluated 11194 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(((string)[i] & 0x80) == 0)Description
TRUEevaluated 11090 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 104 times by 1 test
Evaluated by:
  • Self test
mblength == (size_t)-2Description
TRUEnever evaluated
FALSEevaluated 5447460 times by 1 test
Evaluated by:
  • Self test
mblength == (size_t)-1Description
TRUEevaluated 40 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5447420 times by 1 test
Evaluated by:
  • Self test
0-5447460
1213 }
executed 5870616 times by 1 test: end of block
Executed by:
  • Self test
5870616
1214-
1215#if defined (HANDLE_MULTIBYTE)-
1216 FREE (wcharlist);
executed 33 times by 1 test: sh_xfree((wcharlist), "subst.c", 1216);
Executed by:
  • Self test
wcharlistDescription
TRUEevaluated 33 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 9374762 times by 1 test
Evaluated by:
  • Self test
33-9374762
1217#endif-
1218-
1219 temp = substring (string, *sindex, i);-
1220 *sindex = i;-
1221-
1222 return (temp);
executed 9374795 times by 1 test: return (temp);
Executed by:
  • Self test
9374795
1223}-
1224-
1225/* Extract the $( construct in STRING, and return a new string.-
1226 Start extracting at (SINDEX) as if we had just seen "$(".-
1227 Make (SINDEX) get the position of the matching ")". )-
1228 XFLAGS is additional flags to pass to other extraction functions. */-
1229char *-
1230extract_command_subst (string, sindex, xflags)-
1231 char *string;-
1232 int *sindex;-
1233 int xflags;-
1234{-
1235 char *ret;-
1236-
1237 if (string[*sindex] == LPAREN || (xflags & SX_COMPLETE))
string[*sindex] == '('Description
TRUEevaluated 11460 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 26302 times by 1 test
Evaluated by:
  • Self test
(xflags & 0x0400)Description
TRUEevaluated 41 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 26261 times by 1 test
Evaluated by:
  • Self test
41-26302
1238 return (extract_delimited_string (string, sindex, "$(", "(", ")", xflags|SX_COMMAND)); /*)*/
executed 11501 times by 1 test: return (extract_delimited_string (string, sindex, "$(", "(", ")", xflags|0x0008));
Executed by:
  • Self test
11501
1239 else-
1240 {-
1241 xflags |= (no_longjmp_on_fatal_error ? SX_NOLONGJMP : 0);
no_longjmp_on_fatal_errorDescription
TRUEevaluated 69 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 26192 times by 1 test
Evaluated by:
  • Self test
69-26192
1242 ret = xparse_dolparen (string, string+*sindex, sindex, xflags);-
1243 return ret;
executed 26254 times by 1 test: return ret;
Executed by:
  • Self test
26254
1244 }-
1245}-
1246-
1247/* Extract the $[ construct in STRING, and return a new string. (])-
1248 Start extracting at (SINDEX) as if we had just seen "$[".-
1249 Make (SINDEX) get the position of the matching "]". */-
1250char *-
1251extract_arithmetic_subst (string, sindex)-
1252 char *string;-
1253 int *sindex;-
1254{-
1255 return (extract_delimited_string (string, sindex, "$[", "[", "]", 0)); /*]*/
executed 3 times by 1 test: return (extract_delimited_string (string, sindex, "$[", "[", "]", 0));
Executed by:
  • Self test
3
1256}-
1257-
1258#if defined (PROCESS_SUBSTITUTION)-
1259/* Extract the <( or >( construct in STRING, and return a new string.-
1260 Start extracting at (SINDEX) as if we had just seen "<(".-
1261 Make (SINDEX) get the position of the matching ")". */ /*))*/-
1262char *-
1263extract_process_subst (string, starter, sindex, xflags)-
1264 char *string;-
1265 char *starter;-
1266 int *sindex;-
1267 int xflags;-
1268{-
1269#if 0-
1270 /* XXX - check xflags&SX_COMPLETE here? */-
1271 return (extract_delimited_string (string, sindex, starter, "(", ")", SX_COMMAND));-
1272#else-
1273 xflags |= (no_longjmp_on_fatal_error ? SX_NOLONGJMP : 0);
no_longjmp_on_fatal_errorDescription
TRUEnever evaluated
FALSEevaluated 679046 times by 1 test
Evaluated by:
  • Self test
0-679046
1274 return (xparse_dolparen (string, string+*sindex, sindex, xflags));
executed 679046 times by 1 test: return (xparse_dolparen (string, string+*sindex, sindex, xflags));
Executed by:
  • Self test
679046
1275#endif-
1276}-
1277#endif /* PROCESS_SUBSTITUTION */-
1278-
1279#if defined (ARRAY_VARS)-
1280/* This can be fooled by unquoted right parens in the passed string. If-
1281 each caller verifies that the last character in STRING is a right paren,-
1282 we don't even need to call extract_delimited_string. */-
1283char *-
1284extract_array_assignment_list (string, sindex)-
1285 char *string;-
1286 int *sindex;-
1287{-
1288 int slen;-
1289 char *ret;-
1290-
1291 slen = strlen (string);-
1292 if (string[slen - 1] == RPAREN)
string[slen - 1] == ')'Description
TRUEevaluated 544 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-544
1293 {-
1294 ret = substring (string, *sindex, slen - 1);-
1295 *sindex = slen - 1;-
1296 return ret;
executed 544 times by 1 test: return ret;
Executed by:
  • Self test
544
1297 }-
1298 return 0;
never executed: return 0;
0
1299}-
1300#endif-
1301-
1302/* Extract and create a new string from the contents of STRING, a-
1303 character string delimited with OPENER and CLOSER. SINDEX is-
1304 the address of an int describing the current offset in STRING;-
1305 it should point to just after the first OPENER found. On exit,-
1306 SINDEX gets the position of the last character of the matching CLOSER.-
1307 If OPENER is more than a single character, ALT_OPENER, if non-null,-
1308 contains a character string that can also match CLOSER and thus-
1309 needs to be skipped. */-
1310static char *-
1311extract_delimited_string (string, sindex, opener, alt_opener, closer, flags)-
1312 char *string;-
1313 int *sindex;-
1314 char *opener, *alt_opener, *closer;-
1315 int flags;-
1316{-
1317 int i, c, si;-
1318 size_t slen;-
1319 char *t, *result;-
1320 int pass_character, nesting_level, in_comment;-
1321 int len_closer, len_opener, len_alt_opener;-
1322 DECLARE_MBSTATE;-
1323-
1324 slen = strlen (string + *sindex) + *sindex;-
1325 len_opener = STRLEN (opener);
(opener)[1]Description
TRUEevaluated 12466 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 12704 times by 1 test
Evaluated by:
  • Self test
(opener)[2]Description
TRUEnever evaluated
FALSEevaluated 12466 times by 1 test
Evaluated by:
  • Self test
(opener)Description
TRUEevaluated 25170 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(opener)[0]Description
TRUEevaluated 25170 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-25170
1326 len_alt_opener = STRLEN (alt_opener);
(alt_opener)[1]Description
TRUEnever evaluated
FALSEevaluated 25170 times by 1 test
Evaluated by:
  • Self test
(alt_opener)[2]Description
TRUEnever evaluated
FALSEnever evaluated
(alt_opener)Description
TRUEevaluated 25170 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(alt_opener)[0]Description
TRUEevaluated 25170 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-25170
1327 len_closer = STRLEN (closer);
(closer)[1]Description
TRUEnever evaluated
FALSEevaluated 25170 times by 1 test
Evaluated by:
  • Self test
(closer)[2]Description
TRUEnever evaluated
FALSEnever evaluated
(closer)Description
TRUEevaluated 25170 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(closer)[0]Description
TRUEevaluated 25170 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-25170
1328-
1329 pass_character = in_comment = 0;-
1330-
1331 nesting_level = 1;-
1332 i = *sindex;-
1333-
1334 while (nesting_level)
nesting_levelDescription
TRUEevaluated 107912 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-107912
1335 {-
1336 c = string[i];-
1337-
1338 /* If a recursive call or a call to ADVANCE_CHAR leaves the index beyond-
1339 the end of the string, catch it and cut the loop. */-
1340 if (i > slen)
i > slenDescription
TRUEnever evaluated
FALSEevaluated 107912 times by 1 test
Evaluated by:
  • Self test
0-107912
1341 {-
1342 i = slen;-
1343 c = string[i = slen];-
1344 break;
never executed: break;
0
1345 }-
1346-
1347 if (c == 0)
c == 0Description
TRUEnever evaluated
FALSEevaluated 107912 times by 1 test
Evaluated by:
  • Self test
0-107912
1348 break;
never executed: break;
0
1349-
1350 if (in_comment)
in_commentDescription
TRUEnever evaluated
FALSEevaluated 107912 times by 1 test
Evaluated by:
  • Self test
0-107912
1351 {-
1352 if (c == '\n')
c == '\n'Description
TRUEnever evaluated
FALSEnever evaluated
0
1353 in_comment = 0;
never executed: in_comment = 0;
0
1354 ADVANCE_CHAR (string, slen, i);
never executed: mblength = 1;
never executed: mblength = 1;
never executed: end of block
never executed: end of block
never executed: (i)++;
never executed: (i) += mblength;
never executed: (i)++;
locale_mb_cur_max > 1Description
TRUEnever evaluated
FALSEnever evaluated
_fDescription
TRUEnever evaluated
FALSEnever evaluated
mblength == 0Description
TRUEnever evaluated
FALSEnever evaluated
locale_utf8localeDescription
TRUEnever evaluated
FALSEnever evaluated
(((string)[i] & 0x80) == 0)Description
TRUEnever evaluated
FALSEnever evaluated
mblength == (size_t)-2Description
TRUEnever evaluated
FALSEnever evaluated
mblength == (size_t)-1Description
TRUEnever evaluated
FALSEnever evaluated
0
1355 continue;
never executed: continue;
0
1356 }-
1357-
1358 if (pass_character) /* previous char was backslash */
pass_characterDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 107902 times by 1 test
Evaluated by:
  • Self test
10-107902
1359 {-
1360 pass_character = 0;-
1361 ADVANCE_CHAR (string, slen, i);
never executed: mblength = 1;
executed 10 times by 1 test: mblength = 1;
Executed by:
  • Self test
never executed: end of block
never executed: end of block
never executed: (i)++;
executed 10 times by 1 test: (i) += mblength;
Executed by:
  • Self test
never executed: (i)++;
locale_mb_cur_max > 1Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
_fDescription
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • Self test
mblength == 0Description
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • Self test
locale_utf8localeDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(((string)[i] & 0x80) == 0)Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
mblength == (size_t)-2Description
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • Self test
mblength == (size_t)-1Description
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • Self test
0-10
1362 continue;
executed 10 times by 1 test: continue;
Executed by:
  • Self test
10
1363 }-
1364-
1365 /* Not exactly right yet; should handle shell metacharacters and-
1366 multibyte characters, too. See COMMENT_BEGIN define in parse.y */-
1367 if ((flags & SX_COMMAND) && c == '#' && (i == 0 || string[i - 1] == '\n' || shellblank (string[i - 1])))
(flags & 0x0008)Description
TRUEevaluated 107588 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 314 times by 1 test
Evaluated by:
  • Self test
c == '#'Description
TRUEevaluated 209 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 107379 times by 1 test
Evaluated by:
  • Self test
i == 0Description
TRUEnever evaluated
FALSEevaluated 209 times by 1 test
Evaluated by:
  • Self test
string[i - 1] == '\n'Description
TRUEnever evaluated
FALSEevaluated 209 times by 1 test
Evaluated by:
  • Self test
(sh_syntaxtab[...1])] & 0x2000)Description
TRUEnever evaluated
FALSEevaluated 209 times by 1 test
Evaluated by:
  • Self test
0-107588
1368 {-
1369 in_comment = 1;-
1370 ADVANCE_CHAR (string, slen, i);
never executed: mblength = 1;
never executed: mblength = 1;
never executed: end of block
never executed: end of block
never executed: (i)++;
never executed: (i) += mblength;
never executed: (i)++;
locale_mb_cur_max > 1Description
TRUEnever evaluated
FALSEnever evaluated
_fDescription
TRUEnever evaluated
FALSEnever evaluated
mblength == 0Description
TRUEnever evaluated
FALSEnever evaluated
locale_utf8localeDescription
TRUEnever evaluated
FALSEnever evaluated
(((string)[i] & 0x80) == 0)Description
TRUEnever evaluated
FALSEnever evaluated
mblength == (size_t)-2Description
TRUEnever evaluated
FALSEnever evaluated
mblength == (size_t)-1Description
TRUEnever evaluated
FALSEnever evaluated
0
1371 continue;
never executed: continue;
0
1372 }-
1373 -
1374 if (c == CTLESC || c == '\\')
c == '\001'Description
TRUEnever evaluated
FALSEevaluated 107902 times by 1 test
Evaluated by:
  • Self test
c == '\\'Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 107892 times by 1 test
Evaluated by:
  • Self test
0-107902
1375 {-
1376 pass_character++;-
1377 i++;-
1378 continue;
executed 10 times by 1 test: continue;
Executed by:
  • Self test
10
1379 }-
1380-
1381 /* Process a nested command substitution, but only if we're parsing an-
1382 arithmetic substitution. */-
1383 if ((flags & SX_COMMAND) && string[i] == '$' && string[i+1] == LPAREN)
(flags & 0x0008)Description
TRUEevaluated 107578 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 314 times by 1 test
Evaluated by:
  • Self test
string[i] == '$'Description
TRUEevaluated 726 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 106852 times by 1 test
Evaluated by:
  • Self test
string[i+1] == '('Description
TRUEevaluated 166 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 560 times by 1 test
Evaluated by:
  • Self test
166-107578
1384 {-
1385 si = i + 2;-
1386 t = extract_command_subst (string, &si, flags|SX_NOALLOC);-
1387 CHECK_STRING_OVERRUN (i, si, slen, c);
never executed: break;
executed 166 times by 1 test: ;
Executed by:
  • Self test
si >= slenDescription
TRUEnever evaluated
FALSEevaluated 166 times by 1 test
Evaluated by:
  • Self test
0-166
1388 i = si + 1;-
1389 continue;
executed 166 times by 1 test: continue;
Executed by:
  • Self test
166
1390 }-
1391-
1392 /* Process a nested OPENER. */-
1393 if (STREQN (string + i, opener, len_opener))
never executed: __result = (((const unsigned char *) (const char *) ( string + i ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( opener ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
((len_opener =...ner ))) == 0))Description
TRUEevaluated 521 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 107205 times by 1 test
Evaluated by:
  • Self test
(len_opener == 0)Description
TRUEnever evaluated
FALSEevaluated 107726 times by 1 test
Evaluated by:
  • Self test
(string + i)[0] == (opener)[0]Description
TRUEevaluated 521 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 107205 times by 1 test
Evaluated by:
  • Self test
(__extension__...pener ))) == 0Description
TRUEevaluated 521 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
__builtin_cons...( len_opener )Description
TRUEnever evaluated
FALSEevaluated 521 times by 1 test
Evaluated by:
  • Self test
__builtin_cons...( string + i )Description
TRUEnever evaluated
FALSEnever evaluated
strlen ( strin... len_opener ))Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons...t_p ( opener )Description
TRUEnever evaluated
FALSEnever evaluated
strlen ( opene... len_opener ))Description
TRUEnever evaluated
FALSEnever evaluated
__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-107726
1394 {-
1395 si = i + len_opener;-
1396 t = extract_delimited_string (string, &si, opener, alt_opener, closer, flags|SX_NOALLOC);-
1397 CHECK_STRING_OVERRUN (i, si, slen, c);
never executed: break;
executed 521 times by 1 test: ;
Executed by:
  • Self test
si >= slenDescription
TRUEnever evaluated
FALSEevaluated 521 times by 1 test
Evaluated by:
  • Self test
0-521
1398 i = si + 1;-
1399 continue;
executed 521 times by 1 test: continue;
Executed by:
  • Self test
521
1400 }-
1401-
1402 /* Process a nested ALT_OPENER */-
1403 if (len_alt_opener && STREQN (string + i, alt_opener, len_alt_opener))
never executed: __result = (((const unsigned char *) (const char *) ( string + i ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( alt_opener ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
(len_alt_opener == 0)Description
TRUEnever evaluated
FALSEevaluated 107205 times by 1 test
Evaluated by:
  • Self test
len_alt_openerDescription
TRUEevaluated 107205 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
((len_alt_open...ner ))) == 0))Description
TRUEevaluated 12150 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 95055 times by 1 test
Evaluated by:
  • Self test
(string + i)[0...alt_opener)[0]Description
TRUEevaluated 12150 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 95055 times by 1 test
Evaluated by:
  • Self test
(__extension__...pener ))) == 0Description
TRUEevaluated 12150 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
__builtin_cons...n_alt_opener )Description
TRUEnever evaluated
FALSEevaluated 12150 times by 1 test
Evaluated by:
  • Self test
__builtin_cons...( string + i )Description
TRUEnever evaluated
FALSEnever evaluated
strlen ( strin..._alt_opener ))Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons...( alt_opener )Description
TRUEnever evaluated
FALSEnever evaluated
strlen ( alt_o..._alt_opener ))Description
TRUEnever evaluated
FALSEnever evaluated
__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-107205
1404 {-
1405 si = i + len_alt_opener;-
1406 t = extract_delimited_string (string, &si, alt_opener, alt_opener, closer, flags|SX_NOALLOC);-
1407 CHECK_STRING_OVERRUN (i, si, slen, c);
never executed: break;
executed 12150 times by 1 test: ;
Executed by:
  • Self test
si >= slenDescription
TRUEnever evaluated
FALSEevaluated 12150 times by 1 test
Evaluated by:
  • Self test
0-12150
1408 i = si + 1;-
1409 continue;
executed 12150 times by 1 test: continue;
Executed by:
  • Self test
12150
1410 }-
1411-
1412 /* If the current substring terminates the delimited string, decrement-
1413 the nesting level. */-
1414 if (STREQN (string + i, closer, len_closer))
never executed: __result = (((const unsigned char *) (const char *) ( string + i ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( closer ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
((len_closer =...ser ))) == 0))Description
TRUEevaluated 25170 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 69885 times by 1 test
Evaluated by:
  • Self test
(len_closer == 0)Description
TRUEnever evaluated
FALSEevaluated 95055 times by 1 test
Evaluated by:
  • Self test
(string + i)[0] == (closer)[0]Description
TRUEevaluated 25170 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 69885 times by 1 test
Evaluated by:
  • Self test
(__extension__...loser ))) == 0Description
TRUEevaluated 25170 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
__builtin_cons...( len_closer )Description
TRUEnever evaluated
FALSEevaluated 25170 times by 1 test
Evaluated by:
  • Self test
__builtin_cons...( string + i )Description
TRUEnever evaluated
FALSEnever evaluated
strlen ( strin... len_closer ))Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons...t_p ( closer )Description
TRUEnever evaluated
FALSEnever evaluated
strlen ( close... len_closer ))Description
TRUEnever evaluated
FALSEnever evaluated
__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-95055
1415 {-
1416 i += len_closer - 1; /* move to last byte of the closer */-
1417 nesting_level--;-
1418 if (nesting_level == 0)
nesting_level == 0Description
TRUEevaluated 25170 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-25170
1419 break;
executed 25170 times by 1 test: break;
Executed by:
  • Self test
25170
1420 }
never executed: end of block
0
1421-
1422 /* Pass old-style command substitution through verbatim. */-
1423 if (c == '`')
c == '`'Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 69880 times by 1 test
Evaluated by:
  • Self test
5-69880
1424 {-
1425 si = i + 1;-
1426 t = string_extract (string, &si, "`", flags|SX_NOALLOC);-
1427 CHECK_STRING_OVERRUN (i, si, slen, c);
never executed: break;
executed 5 times by 1 test: ;
Executed by:
  • Self test
si >= slenDescription
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
0-5
1428 i = si + 1;-
1429 continue;
executed 5 times by 1 test: continue;
Executed by:
  • Self test
5
1430 }-
1431-
1432 /* Pass single-quoted and double-quoted strings through verbatim. */-
1433 if (c == '\'' || c == '"')
c == '\''Description
TRUEevaluated 25 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 69855 times by 1 test
Evaluated by:
  • Self test
c == '"'Description
TRUEevaluated 335 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 69520 times by 1 test
Evaluated by:
  • Self test
25-69855
1434 {-
1435 si = i + 1;-
1436 i = (c == '\'') ? skip_single_quoted (string, slen, si, 0)
(c == '\'')Description
TRUEevaluated 25 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 335 times by 1 test
Evaluated by:
  • Self test
25-335
1437 : skip_double_quoted (string, slen, si, 0);-
1438 continue;
executed 360 times by 1 test: continue;
Executed by:
  • Self test
360
1439 }-
1440-
1441 /* move past this character, which was not special. */-
1442 ADVANCE_CHAR (string, slen, i);
executed 68075 times by 1 test: mblength = 1;
Executed by:
  • Self test
executed 560 times by 1 test: mblength = 1;
Executed by:
  • Self test
never executed: end of block
never executed: end of block
never executed: (i)++;
executed 68635 times by 1 test: (i) += mblength;
Executed by:
  • Self test
executed 885 times by 1 test: (i)++;
Executed by:
  • Self test
locale_mb_cur_max > 1Description
TRUEevaluated 68635 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 885 times by 1 test
Evaluated by:
  • Self test
_fDescription
TRUEevaluated 68075 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 560 times by 1 test
Evaluated by:
  • Self test
mblength == 0Description
TRUEnever evaluated
FALSEevaluated 68635 times by 1 test
Evaluated by:
  • Self test
locale_utf8localeDescription
TRUEevaluated 560 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(((string)[i] & 0x80) == 0)Description
TRUEevaluated 560 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
mblength == (size_t)-2Description
TRUEnever evaluated
FALSEevaluated 68635 times by 1 test
Evaluated by:
  • Self test
mblength == (size_t)-1Description
TRUEnever evaluated
FALSEevaluated 68635 times by 1 test
Evaluated by:
  • Self test
0-68635
1443 }
executed 69520 times by 1 test: end of block
Executed by:
  • Self test
69520
1444-
1445 if (c == 0 && nesting_level)
c == 0Description
TRUEnever evaluated
FALSEevaluated 25170 times by 1 test
Evaluated by:
  • Self test
nesting_levelDescription
TRUEnever evaluated
FALSEnever evaluated
0-25170
1446 {-
1447 if (no_longjmp_on_fatal_error == 0)
no_longjmp_on_fatal_error == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1448 {-
1449 last_command_exit_value = EXECUTION_FAILURE;-
1450 report_error (_("bad substitution: no closing `%s' in %s"), closer, string);-
1451 exp_jump_to_top_level (DISCARD);-
1452 }
never executed: end of block
0
1453 else-
1454 {-
1455 *sindex = i;-
1456 return (char *)NULL;
never executed: return (char *) ((void *)0) ;
0
1457 }-
1458 }-
1459-
1460 si = i - *sindex - len_closer + 1;-
1461 if (flags & SX_NOALLOC)
flags & 0x0001Description
TRUEevaluated 13733 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 11437 times by 1 test
Evaluated by:
  • Self test
11437-13733
1462 result = (char *)NULL;
executed 13733 times by 1 test: result = (char *) ((void *)0) ;
Executed by:
  • Self test
13733
1463 else -
1464 {-
1465 result = (char *)xmalloc (1 + si);-
1466 strncpy (result, string + *sindex, si);-
1467 result[si] = '\0';-
1468 }
executed 11437 times by 1 test: end of block
Executed by:
  • Self test
11437
1469 *sindex = i;-
1470-
1471 return (result);
executed 25170 times by 1 test: return (result);
Executed by:
  • Self test
25170
1472}-
1473-
1474/* Extract a parameter expansion expression within ${ and } from STRING.-
1475 Obey the Posix.2 rules for finding the ending `}': count braces while-
1476 skipping over enclosed quoted strings and command substitutions.-
1477 SINDEX is the address of an int describing the current offset in STRING;-
1478 it should point to just after the first `{' found. On exit, SINDEX-
1479 gets the position of the matching `}'. QUOTED is non-zero if this-
1480 occurs inside double quotes. */-
1481/* XXX -- this is very similar to extract_delimited_string -- XXX */-
1482static char *-
1483extract_dollar_brace_string (string, sindex, quoted, flags)-
1484 char *string;-
1485 int *sindex, quoted, flags;-
1486{-
1487 register int i, c;-
1488 size_t slen;-
1489 int pass_character, nesting_level, si, dolbrace_state;-
1490 char *result, *t;-
1491 DECLARE_MBSTATE;-
1492-
1493 pass_character = 0;-
1494 nesting_level = 1;-
1495 slen = strlen (string + *sindex) + *sindex;-
1496-
1497 /* The handling of dolbrace_state needs to agree with the code in parse.y:-
1498 parse_matched_pair(). The different initial value is to handle the-
1499 case where this function is called to parse the word in-
1500 ${param op word} (SX_WORD). */-
1501 dolbrace_state = (flags & SX_WORD) ? DOLBRACE_WORD : DOLBRACE_PARAM;
(flags & 0x0200)Description
TRUEevaluated 2343676 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 45576 times by 1 test
Evaluated by:
  • Self test
45576-2343676
1502 if ((quoted & (Q_HERE_DOCUMENT|Q_DOUBLE_QUOTES)) && (flags & SX_POSIXEXP))
(quoted & (0x002|0x001))Description
TRUEevaluated 56089 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2333163 times by 1 test
Evaluated by:
  • Self test
(flags & 0x0100)Description
TRUEevaluated 749 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 55340 times by 1 test
Evaluated by:
  • Self test
749-2333163
1503 dolbrace_state = DOLBRACE_QUOTE;
executed 749 times by 1 test: dolbrace_state = 0x40;
Executed by:
  • Self test
749
1504-
1505 i = *sindex;-
1506 while (c = string[i])
c = string[i]Description
TRUEevaluated 5532568 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-5532568
1507 {-
1508 if (pass_character)
pass_characterDescription
TRUEevaluated 436 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5532132 times by 1 test
Evaluated by:
  • Self test
436-5532132
1509 {-
1510 pass_character = 0;-
1511 ADVANCE_CHAR (string, slen, i);
executed 375 times by 1 test: mblength = 1;
Executed by:
  • Self test
executed 61 times by 1 test: mblength = 1;
Executed by:
  • Self test
never executed: end of block
never executed: end of block
never executed: (i)++;
executed 436 times by 1 test: (i) += mblength;
Executed by:
  • Self test
never executed: (i)++;
locale_mb_cur_max > 1Description
TRUEevaluated 436 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
_fDescription
TRUEevaluated 375 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 61 times by 1 test
Evaluated by:
  • Self test
mblength == 0Description
TRUEnever evaluated
FALSEevaluated 436 times by 1 test
Evaluated by:
  • Self test
locale_utf8localeDescription
TRUEevaluated 61 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(((string)[i] & 0x80) == 0)Description
TRUEevaluated 61 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
mblength == (size_t)-2Description
TRUEnever evaluated
FALSEevaluated 436 times by 1 test
Evaluated by:
  • Self test
mblength == (size_t)-1Description
TRUEnever evaluated
FALSEevaluated 436 times by 1 test
Evaluated by:
  • Self test
0-436
1512 continue;
executed 436 times by 1 test: continue;
Executed by:
  • Self test
436
1513 }-
1514-
1515 /* CTLESCs and backslashes quote the next character. */-
1516 if (c == CTLESC || c == '\\')
c == '\001'Description
TRUEevaluated 34 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5532098 times by 1 test
Evaluated by:
  • Self test
c == '\\'Description
TRUEevaluated 402 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5531696 times by 1 test
Evaluated by:
  • Self test
34-5532098
1517 {-
1518 pass_character++;-
1519 i++;-
1520 continue;
executed 436 times by 1 test: continue;
Executed by:
  • Self test
436
1521 }-
1522-
1523 if (string[i] == '$' && string[i+1] == LBRACE)
string[i] == '$'Description
TRUEevaluated 5777 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5525919 times by 1 test
Evaluated by:
  • Self test
string[i+1] == '{'Description
TRUEevaluated 98 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5679 times by 1 test
Evaluated by:
  • Self test
98-5525919
1524 {-
1525 nesting_level++;-
1526 i += 2;-
1527 continue;
executed 98 times by 1 test: continue;
Executed by:
  • Self test
98
1528 }-
1529-
1530 if (c == RBRACE)
c == '}'Description
TRUEevaluated 2389350 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3142248 times by 1 test
Evaluated by:
  • Self test
2389350-3142248
1531 {-
1532 nesting_level--;-
1533 if (nesting_level == 0)
nesting_level == 0Description
TRUEevaluated 2389252 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 98 times by 1 test
Evaluated by:
  • Self test
98-2389252
1534 break;
executed 2389252 times by 1 test: break;
Executed by:
  • Self test
2389252
1535 i++;-
1536 continue;
executed 98 times by 1 test: continue;
Executed by:
  • Self test
98
1537 }-
1538-
1539 /* Pass the contents of old-style command substitutions through-
1540 verbatim. */-
1541 if (c == '`')
c == '`'Description
TRUEevaluated 118 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3142130 times by 1 test
Evaluated by:
  • Self test
118-3142130
1542 {-
1543 si = i + 1;-
1544 t = string_extract (string, &si, "`", flags|SX_NOALLOC);-
1545-
1546 CHECK_STRING_OVERRUN (i, si, slen, c);
never executed: break;
executed 118 times by 1 test: ;
Executed by:
  • Self test
si >= slenDescription
TRUEnever evaluated
FALSEevaluated 118 times by 1 test
Evaluated by:
  • Self test
0-118
1547-
1548 i = si + 1;-
1549 continue;
executed 118 times by 1 test: continue;
Executed by:
  • Self test
118
1550 }-
1551-
1552 /* Pass the contents of new-style command substitutions and-
1553 arithmetic substitutions through verbatim. */-
1554 if (string[i] == '$' && string[i+1] == LPAREN)
string[i] == '$'Description
TRUEevaluated 5679 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3136451 times by 1 test
Evaluated by:
  • Self test
string[i+1] == '('Description
TRUEevaluated 70 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5609 times by 1 test
Evaluated by:
  • Self test
70-3136451
1555 {-
1556 si = i + 2;-
1557 t = extract_command_subst (string, &si, flags|SX_NOALLOC);-
1558-
1559 CHECK_STRING_OVERRUN (i, si, slen, c);
never executed: break;
executed 70 times by 1 test: ;
Executed by:
  • Self test
si >= slenDescription
TRUEnever evaluated
FALSEevaluated 70 times by 1 test
Evaluated by:
  • Self test
0-70
1560-
1561 i = si + 1;-
1562 continue;
executed 70 times by 1 test: continue;
Executed by:
  • Self test
70
1563 }-
1564-
1565#if defined (PROCESS_SUBSTITUTION)-
1566 /* Technically this should only work at the start of a word */-
1567 if ((string[i] == '<' || string[i] == '>') && string[i+1] == LPAREN)
string[i] == '<'Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3142057 times by 1 test
Evaluated by:
  • Self test
string[i] == '>'Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3142056 times by 1 test
Evaluated by:
  • Self test
string[i+1] == '('Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
1-3142057
1568 {-
1569 si = i + 2;-
1570 t = extract_process_subst (string, (string[i] == '<' ? "<(" : ">)"), &si, flags|SX_NOALLOC);-
1571-
1572 CHECK_STRING_OVERRUN (i, si, slen, c);
never executed: break;
executed 2 times by 1 test: ;
Executed by:
  • Self test
si >= slenDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
0-2
1573-
1574 i = si + 1;-
1575 continue;
executed 2 times by 1 test: continue;
Executed by:
  • Self test
2
1576 }-
1577#endif-
1578-
1579 /* Pass the contents of double-quoted strings through verbatim. */-
1580 if (c == '"')
c == '"'Description
TRUEevaluated 2428 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3139630 times by 1 test
Evaluated by:
  • Self test
2428-3139630
1581 {-
1582 si = i + 1;-
1583 i = skip_double_quoted (string, slen, si, 0);-
1584 /* skip_XXX_quoted leaves index one past close quote */-
1585 continue;
executed 2428 times by 1 test: continue;
Executed by:
  • Self test
2428
1586 }-
1587-
1588 if (c == '\'')
c == '\''Description
TRUEevaluated 2315940 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 823690 times by 1 test
Evaluated by:
  • Self test
823690-2315940
1589 {-
1590/*itrace("extract_dollar_brace_string: c == single quote flags = %d quoted = %d dolbrace_state = %d", flags, quoted, dolbrace_state);*/-
1591 if (posixly_correct && shell_compatibility_level > 42 && dolbrace_state != DOLBRACE_QUOTE && (quoted & (Q_HERE_DOCUMENT|Q_DOUBLE_QUOTES)))
posixly_correctDescription
TRUEevaluated 38 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2315902 times by 1 test
Evaluated by:
  • Self test
shell_compatibility_level > 42Description
TRUEevaluated 38 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
dolbrace_state != 0x40Description
TRUEevaluated 36 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
(quoted & (0x002|0x001))Description
TRUEevaluated 28 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
0-2315902
1592 ADVANCE_CHAR (string, slen, i);
executed 28 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: (i)++;
executed 28 times by 1 test: (i) += mblength;
Executed by:
  • Self test
never executed: (i)++;
executed 28 times by 1 test: end of block
Executed by:
  • Self test
locale_mb_cur_max > 1Description
TRUEevaluated 28 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
_fDescription
TRUEevaluated 28 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
mblength == 0Description
TRUEnever evaluated
FALSEevaluated 28 times by 1 test
Evaluated by:
  • Self test
locale_utf8localeDescription
TRUEnever evaluated
FALSEnever evaluated
(((string)[i] & 0x80) == 0)Description
TRUEnever evaluated
FALSEnever evaluated
mblength == (size_t)-2Description
TRUEnever evaluated
FALSEevaluated 28 times by 1 test
Evaluated by:
  • Self test
mblength == (size_t)-1Description
TRUEnever evaluated
FALSEevaluated 28 times by 1 test
Evaluated by:
  • Self test
0-28
1593 else-
1594 {-
1595 si = i + 1;-
1596 i = skip_single_quoted (string, slen, si, 0);-
1597 }
executed 2315912 times by 1 test: end of block
Executed by:
  • Self test
2315912
1598-
1599 continue;
executed 2315940 times by 1 test: continue;
Executed by:
  • Self test
2315940
1600 }-
1601-
1602#if defined (ARRAY_VARS)-
1603 /* XXX - bash-5.0 */-
1604 if (c == LBRACK && dolbrace_state == DOLBRACE_PARAM)
c == '['Description
TRUEevaluated 4895 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 818795 times by 1 test
Evaluated by:
  • Self test
dolbrace_state == 0x01Description
TRUEevaluated 4737 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 158 times by 1 test
Evaluated by:
  • Self test
158-818795
1605 {-
1606 si = skipsubscript (string, i, 0);-
1607 CHECK_STRING_OVERRUN (i, si, slen, c);
never executed: break;
executed 4737 times by 1 test: ;
Executed by:
  • Self test
si >= slenDescription
TRUEnever evaluated
FALSEevaluated 4737 times by 1 test
Evaluated by:
  • Self test
0-4737
1608 if (string[si] == RBRACK)
string[si] == ']'Description
TRUEevaluated 4737 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-4737
1609 c = string[i = si];
executed 4737 times by 1 test: c = string[i = si];
Executed by:
  • Self test
4737
1610 }
executed 4737 times by 1 test: end of block
Executed by:
  • Self test
4737
1611#endif-
1612-
1613 /* move past this character, which was not special. */-
1614 ADVANCE_CHAR (string, slen, i);
executed 814730 times by 1 test: mblength = 1;
Executed by:
  • Self test
executed 8189 times by 1 test: mblength = 1;
Executed by:
  • Self test
never executed: end of block
never executed: end of block
never executed: (i)++;
executed 822919 times by 1 test: (i) += mblength;
Executed by:
  • Self test
executed 771 times by 1 test: (i)++;
Executed by:
  • Self test
locale_mb_cur_max > 1Description
TRUEevaluated 822919 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 771 times by 1 test
Evaluated by:
  • Self test
_fDescription
TRUEevaluated 814730 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8189 times by 1 test
Evaluated by:
  • Self test
mblength == 0Description
TRUEnever evaluated
FALSEevaluated 822919 times by 1 test
Evaluated by:
  • Self test
locale_utf8localeDescription
TRUEevaluated 8189 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(((string)[i] & 0x80) == 0)Description
TRUEevaluated 8189 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
mblength == (size_t)-2Description
TRUEnever evaluated
FALSEevaluated 822919 times by 1 test
Evaluated by:
  • Self test
mblength == (size_t)-1Description
TRUEnever evaluated
FALSEevaluated 822919 times by 1 test
Evaluated by:
  • Self test
0-822919
1615-
1616 /* This logic must agree with parse.y:parse_matched_pair, since they-
1617 share the same defines. */-
1618 if (dolbrace_state == DOLBRACE_PARAM && c == '%' && (i - *sindex) > 1)
dolbrace_state == 0x01Description
TRUEevaluated 140413 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 683277 times by 1 test
Evaluated by:
  • Self test
c == '%'Description
TRUEevaluated 60 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 140353 times by 1 test
Evaluated by:
  • Self test
(i - *sindex) > 1Description
TRUEevaluated 60 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-683277
1619 dolbrace_state = DOLBRACE_QUOTE;
executed 60 times by 1 test: dolbrace_state = 0x40;
Executed by:
  • Self test
60
1620 else if (dolbrace_state == DOLBRACE_PARAM && c == '#' && (i - *sindex) > 1)
dolbrace_state == 0x01Description
TRUEevaluated 140353 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 683277 times by 1 test
Evaluated by:
  • Self test
c == '#'Description
TRUEevaluated 138 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 140215 times by 1 test
Evaluated by:
  • Self test
(i - *sindex) > 1Description
TRUEevaluated 88 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 50 times by 1 test
Evaluated by:
  • Self test
50-683277
1621 dolbrace_state = DOLBRACE_QUOTE;
executed 88 times by 1 test: dolbrace_state = 0x40;
Executed by:
  • Self test
88
1622 else if (dolbrace_state == DOLBRACE_PARAM && c == '/' && (i - *sindex) > 1)
dolbrace_state == 0x01Description
TRUEevaluated 140265 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 683277 times by 1 test
Evaluated by:
  • Self test
c == '/'Description
TRUEevaluated 232 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 140033 times by 1 test
Evaluated by:
  • Self test
(i - *sindex) > 1Description
TRUEevaluated 232 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-683277
1623 dolbrace_state = DOLBRACE_QUOTE2; /* XXX */
executed 232 times by 1 test: dolbrace_state = 0x80;
Executed by:
  • Self test
232
1624 else if (dolbrace_state == DOLBRACE_PARAM && c == '^' && (i - *sindex) > 1)
dolbrace_state == 0x01Description
TRUEevaluated 140033 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 683277 times by 1 test
Evaluated by:
  • Self test
c == '^'Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 140024 times by 1 test
Evaluated by:
  • Self test
(i - *sindex) > 1Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-683277
1625 dolbrace_state = DOLBRACE_QUOTE;
executed 9 times by 1 test: dolbrace_state = 0x40;
Executed by:
  • Self test
9
1626 else if (dolbrace_state == DOLBRACE_PARAM && c == ',' && (i - *sindex) > 1)
dolbrace_state == 0x01Description
TRUEevaluated 140024 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 683277 times by 1 test
Evaluated by:
  • Self test
c == ','Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 140012 times by 1 test
Evaluated by:
  • Self test
(i - *sindex) > 1Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-683277
1627 dolbrace_state = DOLBRACE_QUOTE;
executed 12 times by 1 test: dolbrace_state = 0x40;
Executed by:
  • Self test
12
1628 /* This is intended to handle all of the [:]op expansions and the substring/-
1629 length/pattern removal/pattern substitution expansions. */-
1630 else if (dolbrace_state == DOLBRACE_PARAM && strchr ("#%^,~:-=?+/", c) != 0)
dolbrace_state == 0x01Description
TRUEevaluated 140012 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 683277 times by 1 test
Evaluated by:
  • Self test
(__extension__..." , c ))) != 0Description
TRUEevaluated 25839 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 114173 times by 1 test
Evaluated by:
  • Self test
__builtin_constant_p ( c )Description
TRUEnever evaluated
FALSEevaluated 140012 times by 1 test
Evaluated by:
  • Self test
!__builtin_con...#%^,~:-=?+/" )Description
TRUEnever evaluated
FALSEnever evaluated
( c ) == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
0-683277
1631 dolbrace_state = DOLBRACE_OP;
executed 25839 times by 1 test: dolbrace_state = 0x02;
Executed by:
  • Self test
25839
1632 else if (dolbrace_state == DOLBRACE_OP && strchr ("#%^,~:-=?+/", c) == 0)
dolbrace_state == 0x02Description
TRUEevaluated 50051 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 747399 times by 1 test
Evaluated by:
  • Self test
(__extension__..." , c ))) == 0Description
TRUEevaluated 25518 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 24533 times by 1 test
Evaluated by:
  • Self test
__builtin_constant_p ( c )Description
TRUEnever evaluated
FALSEevaluated 50051 times by 1 test
Evaluated by:
  • Self test
!__builtin_con...#%^,~:-=?+/" )Description
TRUEnever evaluated
FALSEnever evaluated
( c ) == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
0-747399
1633 dolbrace_state = DOLBRACE_WORD;
executed 25518 times by 1 test: dolbrace_state = 0x04;
Executed by:
  • Self test
25518
1634 }
executed 823690 times by 1 test: end of block
Executed by:
  • Self test
823690
1635-
1636 if (c == 0 && nesting_level)
c == 0Description
TRUEnever evaluated
FALSEevaluated 2389252 times by 1 test
Evaluated by:
  • Self test
nesting_levelDescription
TRUEnever evaluated
FALSEnever evaluated
0-2389252
1637 {-
1638 if (no_longjmp_on_fatal_error == 0)
no_longjmp_on_fatal_error == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1639 { /* { */-
1640 last_command_exit_value = EXECUTION_FAILURE;-
1641 report_error (_("bad substitution: no closing `%s' in %s"), "}", string);-
1642 exp_jump_to_top_level (DISCARD);-
1643 }
never executed: end of block
0
1644 else-
1645 {-
1646 *sindex = i;-
1647 return ((char *)NULL);
never executed: return ((char *) ((void *)0) );
0
1648 }-
1649 }-
1650-
1651 result = (flags & SX_NOALLOC) ? (char *)NULL : substring (string, *sindex, i);
(flags & 0x0001)Description
TRUEevaluated 15504 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2373748 times by 1 test
Evaluated by:
  • Self test
15504-2373748
1652 *sindex = i;-
1653-
1654 return (result);
executed 2389252 times by 1 test: return (result);
Executed by:
  • Self test
2389252
1655}-
1656-
1657/* Remove backslashes which are quoting backquotes from STRING. Modifies-
1658 STRING, and returns a pointer to it. */-
1659char *-
1660de_backslash (string)-
1661 char *string;-
1662{-
1663 register size_t slen;-
1664 register int i, j, prev_i;-
1665 DECLARE_MBSTATE;-
1666-
1667 slen = strlen (string);-
1668 i = j = 0;-
1669-
1670 /* Loop copying string[i] to string[j], i >= j. */-
1671 while (i < slen)
i < slenDescription
TRUEevaluated 203467366 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3231118 times by 1 test
Evaluated by:
  • Self test
3231118-203467366
1672 {-
1673 if (string[i] == '\\' && (string[i + 1] == '`' || string[i + 1] == '\\' ||
string[i] == '\\'Description
TRUEevaluated 350 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 203467016 times by 1 test
Evaluated by:
  • Self test
string[i + 1] == '`'Description
TRUEevaluated 22 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 328 times by 1 test
Evaluated by:
  • Self test
string[i + 1] == '\\'Description
TRUEevaluated 174 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 154 times by 1 test
Evaluated by:
  • Self test
22-203467016
1674 string[i + 1] == '$'))
string[i + 1] == '$'Description
TRUEevaluated 39 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 115 times by 1 test
Evaluated by:
  • Self test
39-115
1675 i++;
executed 235 times by 1 test: i++;
Executed by:
  • Self test
235
1676 prev_i = i;-
1677 ADVANCE_CHAR (string, slen, i);
executed 190545729 times by 1 test: mblength = 1;
Executed by:
  • Self test
executed 12918068 times by 1 test: mblength = 1;
Executed by:
  • Self test
never executed: end of block
never executed: end of block
never executed: (i)++;
executed 203463797 times by 1 test: (i) += mblength;
Executed by:
  • Self test
executed 3569 times by 1 test: (i)++;
Executed by:
  • Self test
locale_mb_cur_max > 1Description
TRUEevaluated 203463797 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3569 times by 1 test
Evaluated by:
  • Self test
_fDescription
TRUEevaluated 190545729 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 12918068 times by 1 test
Evaluated by:
  • Self test
mblength == 0Description
TRUEnever evaluated
FALSEevaluated 203463797 times by 1 test
Evaluated by:
  • Self test
locale_utf8localeDescription
TRUEevaluated 12918068 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(((string)[i] & 0x80) == 0)Description
TRUEevaluated 12918068 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
mblength == (size_t)-2Description
TRUEnever evaluated
FALSEevaluated 203463797 times by 1 test
Evaluated by:
  • Self test
mblength == (size_t)-1Description
TRUEnever evaluated
FALSEevaluated 203463797 times by 1 test
Evaluated by:
  • Self test
0-203463797
1678 if (j < prev_i)
j < prev_iDescription
TRUEevaluated 1608 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 203465758 times by 1 test
Evaluated by:
  • Self test
1608-203465758
1679 do string[j++] = string[prev_i++]; while (prev_i < i);
executed 1608 times by 1 test: string[j++] = string[prev_i++];
Executed by:
  • Self test
prev_i < iDescription
TRUEnever evaluated
FALSEevaluated 1608 times by 1 test
Evaluated by:
  • Self test
0-1608
1680 else-
1681 j = i;
executed 203465758 times by 1 test: j = i;
Executed by:
  • Self test
203465758
1682 }
executed 203467366 times by 1 test: end of block
Executed by:
  • Self test
203467366
1683 string[j] = '\0';-
1684-
1685 return (string);
executed 3231118 times by 1 test: return (string);
Executed by:
  • Self test
3231118
1686}-
1687-
1688#if 0-
1689/*UNUSED*/-
1690/* Replace instances of \! in a string with !. */-
1691void-
1692unquote_bang (string)-
1693 char *string;-
1694{-
1695 register int i, j;-
1696 register char *temp;-
1697-
1698 temp = (char *)xmalloc (1 + strlen (string));-
1699-
1700 for (i = 0, j = 0; (temp[j] = string[i]); i++, j++)-
1701 {-
1702 if (string[i] == '\\' && string[i + 1] == '!')-
1703 {-
1704 temp[j] = '!';-
1705 i++;-
1706 }-
1707 }-
1708 strcpy (string, temp);-
1709 free (temp);-
1710}-
1711#endif-
1712-
1713#define CQ_RETURN(x) do { no_longjmp_on_fatal_error = oldjmp; return (x); } while (0)-
1714-
1715/* This function assumes s[i] == open; returns with s[ret] == close; used to-
1716 parse array subscripts. FLAGS & 1 means to not attempt to skip over-
1717 matched pairs of quotes or backquotes, or skip word expansions; it is-
1718 intended to be used after expansion has been performed and during final-
1719 assignment parsing (see arrayfunc.c:assign_compound_array_list()) or-
1720 during execution by a builtin which has already undergone word expansion. */-
1721static int-
1722skip_matched_pair (string, start, open, close, flags)-
1723 const char *string;-
1724 int start, open, close, flags;-
1725{-
1726 int i, pass_next, backq, si, c, count, oldjmp;-
1727 size_t slen;-
1728