OpenCoverage

expr.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/expr.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* expr.c -- arithmetic expression evaluation. */-
2-
3/* Copyright (C) 1990-2015 Free Software Foundation, Inc.-
4-
5 This file is part of GNU Bash, the Bourne Again SHell.-
6-
7 Bash is free software: you can redistribute it and/or modify-
8 it under the terms of the GNU General Public License as published by-
9 the Free Software Foundation, either version 3 of the License, or-
10 (at your option) any later version.-
11-
12 Bash is distributed in the hope that it will be useful,-
13 but WITHOUT ANY WARRANTY; without even the implied warranty of-
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
15 GNU General Public License for more details.-
16-
17 You should have received a copy of the GNU General Public License-
18 along with Bash. If not, see <http://www.gnu.org/licenses/>.-
19*/-
20-
21/*-
22 All arithmetic is done as intmax_t integers with no checking for overflow-
23 (though division by 0 is caught and flagged as an error).-
24-
25 The following operators are handled, grouped into a set of levels in-
26 order of decreasing precedence.-
27-
28 "id++", "id--" [post-increment and post-decrement]-
29 "++id", "--id" [pre-increment and pre-decrement]-
30 "-", "+" [(unary operators)]-
31 "!", "~"-
32 "**" [(exponentiation)]-
33 "*", "/", "%"-
34 "+", "-"-
35 "<<", ">>"-
36 "<=", ">=", "<", ">"-
37 "==", "!="-
38 "&"-
39 "^"-
40 "|"-
41 "&&"-
42 "||"-
43 "expr ? expr : expr"-
44 "=", "*=", "/=", "%=", "+=", "-=", "<<=", ">>=", "&=", "^=", "|="-
45 , [comma]-
46-
47 (Note that most of these operators have special meaning to bash, and an-
48 entire expression should be quoted, e.g. "a=$a+1" or "a=a+1" to ensure-
49 that it is passed intact to the evaluator when using `let'. When using-
50 the $[] or $(( )) forms, the text between the `[' and `]' or `((' and `))'-
51 is treated as if in double quotes.)-
52-
53 Sub-expressions within parentheses have a precedence level greater than-
54 all of the above levels and are evaluated first. Within a single prece--
55 dence group, evaluation is left-to-right, except for the arithmetic-
56 assignment operator (`='), which is evaluated right-to-left (as in C).-
57-
58 The expression evaluator returns the value of the expression (assignment-
59 statements have as a value what is returned by the RHS). The `let'-
60 builtin, on the other hand, returns 0 if the last expression evaluates to-
61 a non-zero, and 1 otherwise.-
62-
63 Implementation is a recursive-descent parser.-
64-
65 Chet Ramey-
66 chet@po.cwru.edu-
67*/-
68-
69#include "config.h"-
70-
71#include <stdio.h>-
72#include "bashansi.h"-
73-
74#if defined (HAVE_UNISTD_H)-
75# ifdef _MINIX-
76# include <sys/types.h>-
77# endif-
78# include <unistd.h>-
79#endif-
80-
81#include "chartypes.h"-
82#include "bashintl.h"-
83-
84#include "shell.h"-
85#include "arrayfunc.h"-
86#include "execute_cmd.h"-
87#include "flags.h"-
88#include "subst.h"-
89#include "typemax.h" /* INTMAX_MAX, INTMAX_MIN */-
90-
91/* Because of the $((...)) construct, expressions may include newlines.-
92 Here is a macro which accepts newlines, tabs and spaces as whitespace. */-
93#define cr_whitespace(c) (whitespace(c) || ((c) == '\n'))-
94-
95/* Size be which the expression stack grows when necessary. */-
96#define EXPR_STACK_GROW_SIZE 10-
97-
98/* Maximum amount of recursion allowed. This prevents a non-integer-
99 variable such as "num=num+2" from infinitely adding to itself when-
100 "let num=num+2" is given. */-
101#define MAX_EXPR_RECURSION_LEVEL 1024-
102-
103/* The Tokens. Singing "The Lion Sleeps Tonight". */-
104-
105#define EQEQ 1 /* "==" */-
106#define NEQ 2 /* "!=" */-
107#define LEQ 3 /* "<=" */-
108#define GEQ 4 /* ">=" */-
109#define STR 5 /* string */-
110#define NUM 6 /* number */-
111#define LAND 7 /* "&&" Logical AND */-
112#define LOR 8 /* "||" Logical OR */-
113#define LSH 9 /* "<<" Left SHift */-
114#define RSH 10 /* ">>" Right SHift */-
115#define OP_ASSIGN 11 /* op= expassign as in Posix.2 */-
116#define COND 12 /* exp1 ? exp2 : exp3 */-
117#define POWER 13 /* exp1**exp2 */-
118#define PREINC 14 /* ++var */-
119#define PREDEC 15 /* --var */-
120#define POSTINC 16 /* var++ */-
121#define POSTDEC 17 /* var-- */-
122#define EQ '='-
123#define GT '>'-
124#define LT '<'-
125#define PLUS '+'-
126#define MINUS '-'-
127#define MUL '*'-
128#define DIV '/'-
129#define MOD '%'-
130#define NOT '!'-
131#define LPAR '('-
132#define RPAR ')'-
133#define BAND '&' /* Bitwise AND */-
134#define BOR '|' /* Bitwise OR. */-
135#define BXOR '^' /* Bitwise eXclusive OR. */-
136#define BNOT '~' /* Bitwise NOT; Two's complement. */-
137#define QUES '?'-
138#define COL ':'-
139#define COMMA ','-
140-
141/* This should be the function corresponding to the operator with the-
142 highest precedence. */-
143#define EXP_HIGHEST expcomma-
144-
145#ifndef MAX_INT_LEN-
146# define MAX_INT_LEN 32-
147#endif-
148-
149struct lvalue-
150{-
151 char *tokstr; /* possibly-rewritten lvalue if not NULL */-
152 intmax_t tokval; /* expression evaluated value */-
153 SHELL_VAR *tokvar; /* variable described by array or var reference */-
154 intmax_t ind; /* array index if not -1 */-
155};-
156-
157/* A structure defining a single expression context. */-
158typedef struct {-
159 int curtok, lasttok;-
160 char *expression, *tp, *lasttp;-
161 intmax_t tokval;-
162 char *tokstr;-
163 int noeval;-
164 struct lvalue lval;-
165} EXPR_CONTEXT;-
166-
167static char *expression; /* The current expression */-
168static char *tp; /* token lexical position */-
169static char *lasttp; /* pointer to last token position */-
170static int curtok; /* the current token */-
171static int lasttok; /* the previous token */-
172static int assigntok; /* the OP in OP= */-
173static char *tokstr; /* current token string */-
174static intmax_t tokval; /* current token value */-
175static int noeval; /* set to 1 if no assignment to be done */-
176static procenv_t evalbuf;-
177-
178/* set to 1 if the expression has already been run through word expansion */-
179static int already_expanded;-
180-
181static struct lvalue curlval = {0, 0, 0, -1};-
182static struct lvalue lastlval = {0, 0, 0, -1};-
183-
184static int _is_arithop __P((int));-
185static void readtok __P((void)); /* lexical analyzer */-
186-
187static void init_lvalue __P((struct lvalue *));-
188static struct lvalue *alloc_lvalue __P((void));-
189static void free_lvalue __P((struct lvalue *));-
190-
191static intmax_t expr_streval __P((char *, int, struct lvalue *));-
192static intmax_t strlong __P((char *));-
193static void evalerror __P((const char *));-
194-
195static void pushexp __P((void));-
196static void popexp __P((void));-
197static void expr_unwind __P((void));-
198static void expr_bind_variable __P((char *, char *));-
199#if defined (ARRAY_VARS)-
200static void expr_bind_array_element __P((char *, arrayind_t, char *));-
201#endif-
202-
203static intmax_t subexpr __P((char *));-
204-
205static intmax_t expcomma __P((void));-
206static intmax_t expassign __P((void));-
207static intmax_t expcond __P((void));-
208static intmax_t explor __P((void));-
209static intmax_t expland __P((void));-
210static intmax_t expbor __P((void));-
211static intmax_t expbxor __P((void));-
212static intmax_t expband __P((void));-
213static intmax_t exp5 __P((void));-
214static intmax_t exp4 __P((void));-
215static intmax_t expshift __P((void));-
216static intmax_t exp3 __P((void));-
217static intmax_t exp2 __P((void));-
218static intmax_t exppower __P((void));-
219static intmax_t exp1 __P((void));-
220static intmax_t exp0 __P((void));-
221-
222/* Global var which contains the stack of expression contexts. */-
223static EXPR_CONTEXT **expr_stack;-
224static int expr_depth; /* Location in the stack. */-
225static int expr_stack_size; /* Number of slots already allocated. */-
226-
227#if defined (ARRAY_VARS)-
228extern const char * const bash_badsub_errmsg;-
229#endif-
230-
231#define SAVETOK(X) \-
232 do { \-
233 (X)->curtok = curtok; \-
234 (X)->lasttok = lasttok; \-
235 (X)->tp = tp; \-
236 (X)->lasttp = lasttp; \-
237 (X)->tokval = tokval; \-
238 (X)->tokstr = tokstr; \-
239 (X)->noeval = noeval; \-
240 (X)->lval = curlval; \-
241 } while (0)-
242-
243#define RESTORETOK(X) \-
244 do { \-
245 curtok = (X)->curtok; \-
246 lasttok = (X)->lasttok; \-
247 tp = (X)->tp; \-
248 lasttp = (X)->lasttp; \-
249 tokval = (X)->tokval; \-
250 tokstr = (X)->tokstr; \-
251 noeval = (X)->noeval; \-
252 curlval = (X)->lval; \-
253 } while (0)-
254-
255/* Push and save away the contents of the globals describing the-
256 current expression context. */-
257static void-
258pushexp ()-
259{-
260 EXPR_CONTEXT *context;-
261-
262 if (expr_depth >= MAX_EXPR_RECURSION_LEVEL)
expr_depth >= 1024Description
TRUEnever evaluated
FALSEevaluated 14508109 times by 1 test
Evaluated by:
  • Self test
0-14508109
263 evalerror (_("expression recursion level exceeded"));
never executed: evalerror ( dcgettext (((void *)0), "expression recursion level exceeded" , 5) );
0
264-
265 if (expr_depth >= expr_stack_size)
expr_depth >= expr_stack_sizeDescription
TRUEevaluated 4344 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 14503765 times by 1 test
Evaluated by:
  • Self test
4344-14503765
266 {-
267 expr_stack_size += EXPR_STACK_GROW_SIZE;-
268 expr_stack = (EXPR_CONTEXT **)xrealloc (expr_stack, expr_stack_size * sizeof (EXPR_CONTEXT *));-
269 }
executed 4344 times by 1 test: end of block
Executed by:
  • Self test
4344
270-
271 context = (EXPR_CONTEXT *)xmalloc (sizeof (EXPR_CONTEXT));-
272-
273 context->expression = expression;-
274 SAVETOK(context);-
275-
276 expr_stack[expr_depth++] = context;-
277}
executed 14508109 times by 1 test: end of block
Executed by:
  • Self test
14508109
278-
279/* Pop the the contents of the expression context stack into the-
280 globals describing the current expression context. */-
281static void-
282popexp ()-
283{-
284 EXPR_CONTEXT *context;-
285-
286 if (expr_depth <= 0)
expr_depth <= 0Description
TRUEnever evaluated
FALSEevaluated 14507889 times by 1 test
Evaluated by:
  • Self test
0-14507889
287 {-
288 /* See the comment at the top of evalexp() for an explanation of why-
289 this is done. */-
290 expression = lasttp = 0;-
291 evalerror (_("recursion stack underflow"));-
292 }
never executed: end of block
0
293-
294 context = expr_stack[--expr_depth];-
295-
296 expression = context->expression;-
297 RESTORETOK (context);-
298-
299 free (context);-
300}
executed 14507889 times by 1 test: end of block
Executed by:
  • Self test
14507889
301-
302static void-
303expr_unwind ()-
304{-
305 while (--expr_depth > 0)
--expr_depth > 0Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 209 times by 1 test
Evaluated by:
  • Self test
7-209
306 {-
307 if (expr_stack[expr_depth]->tokstr)
expr_stack[expr_depth]->tokstrDescription
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-7
308 free (expr_stack[expr_depth]->tokstr);
executed 7 times by 1 test: sh_xfree((expr_stack[expr_depth]->tokstr), "expr.c", 308);
Executed by:
  • Self test
7
309-
310 if (expr_stack[expr_depth]->expression)
expr_stack[exp...h]->expressionDescription
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-7
311 free (expr_stack[expr_depth]->expression);
executed 7 times by 1 test: sh_xfree((expr_stack[expr_depth]->expression), "expr.c", 311);
Executed by:
  • Self test
7
312-
313 free (expr_stack[expr_depth]);-
314 }
executed 7 times by 1 test: end of block
Executed by:
  • Self test
7
315 if (expr_depth == 0)
expr_depth == 0Description
TRUEevaluated 209 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-209
316 free (expr_stack[expr_depth]); /* free the allocated EXPR_CONTEXT */
executed 209 times by 1 test: sh_xfree((expr_stack[expr_depth]), "expr.c", 316);
Executed by:
  • Self test
209
317-
318 noeval = 0; /* XXX */-
319}
executed 209 times by 1 test: end of block
Executed by:
  • Self test
209
320-
321static void-
322expr_bind_variable (lhs, rhs)-
323 char *lhs, *rhs;-
324{-
325 SHELL_VAR *v;-
326 int aflags;-
327-
328#if defined (ARRAY_VARS)-
329 aflags = (assoc_expand_once && already_expanded) ? ASS_NOEXPAND : 0;
assoc_expand_onceDescription
TRUEevaluated 13 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7183335 times by 1 test
Evaluated by:
  • Self test
already_expandedDescription
TRUEevaluated 13 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-7183335
330#else-
331 aflags = 0;-
332#endif-
333 v = bind_int_variable (lhs, rhs, aflags);-
334 if (v && (readonly_p (v) || noassign_p (v)))
vDescription
TRUEevaluated 7183341 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
((((v)->attrib... (0x0000002)))Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7183339 times by 1 test
Evaluated by:
  • Self test
((((v)->attrib... (0x0004000)))Description
TRUEnever evaluated
FALSEevaluated 7183339 times by 1 test
Evaluated by:
  • Self test
0-7183341
335 sh_longjmp (evalbuf, 1); /* variable assignment error */
executed 2 times by 1 test: siglongjmp((evalbuf), (1));
Executed by:
  • Self test
2
336 stupidly_hack_special_variables (lhs);-
337}
executed 7183345 times by 1 test: end of block
Executed by:
  • Self test
7183345
338-
339#if defined (ARRAY_VARS)-
340/* Rewrite tok, which is of the form vname[expression], to vname[ind], where-
341 IND is the already-calculated value of expression. */-
342static void-
343expr_bind_array_element (tok, ind, rhs)-
344 char *tok;-
345 arrayind_t ind;-
346 char *rhs;-
347{-
348 char *lhs, *vname;-
349 size_t llen;-
350 char ibuf[INT_STRLEN_BOUND (arrayind_t) + 1], *istr;-
351-
352 istr = fmtumax (ind, 10, ibuf, sizeof (ibuf), 0);-
353 vname = array_variable_name (tok, 0, (char **)NULL, (int *)NULL);-
354-
355 llen = strlen (vname) + sizeof (ibuf) + 3;-
356 lhs = xmalloc (llen);-
357-
358 sprintf (lhs, "%s[%s]", vname, istr); /* XXX */-
359 -
360/*itrace("expr_bind_array_element: %s=%s", lhs, rhs);*/-
361 expr_bind_variable (lhs, rhs);-
362 free (vname);-
363 free (lhs);-
364}
executed 10010 times by 1 test: end of block
Executed by:
  • Self test
10010
365#endif /* ARRAY_VARS */-
366-
367/* Evaluate EXPR, and return the arithmetic result. If VALIDP is-
368 non-null, a zero is stored into the location to which it points-
369 if the expression is invalid, non-zero otherwise. If a non-zero-
370 value is returned in *VALIDP, the return value of evalexp() may-
371 be used.-
372-
373 The `while' loop after the longjmp is caught relies on the above-
374 implementation of pushexp and popexp leaving in expr_stack[0] the-
375 values that the variables had when the program started. That is,-
376 the first things saved are the initial values of the variables that-
377 were assigned at program startup or by the compiler. Therefore, it is-
378 safe to let the loop terminate when expr_depth == 0, without freeing up-
379 any of the expr_depth[0] stuff. */-
380intmax_t-
381evalexp (expr, flags, validp)-
382 char *expr;-
383 int flags;-
384 int *validp;-
385{-
386 intmax_t val;-
387 int c;-
388 procenv_t oevalbuf;-
389-
390 val = 0;-
391 noeval = 0;-
392 already_expanded = (flags&EXP_EXPANDED);-
393-
394 FASTCOPY (evalbuf, oevalbuf, sizeof (evalbuf));-
395-
396 c = setjmp_nosigs (evalbuf);-
397-
398 if (c)
cDescription
TRUEevaluated 209 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7256486 times by 1 test
Evaluated by:
  • Self test
209-7256486
399 {-
400 FREE (tokstr);
executed 82 times by 1 test: sh_xfree((tokstr), "expr.c", 400);
Executed by:
  • Self test
tokstrDescription
TRUEevaluated 82 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 127 times by 1 test
Evaluated by:
  • Self test
82-127
401 FREE (expression);
executed 209 times by 1 test: sh_xfree((expression), "expr.c", 401);
Executed by:
  • Self test
expressionDescription
TRUEevaluated 209 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-209
402 tokstr = expression = (char *)NULL;-
403-
404 expr_unwind ();-
405 expr_depth = 0; /* XXX - make sure */-
406-
407 /* We copy in case we've called evalexp recursively */-
408 FASTCOPY (oevalbuf, evalbuf, sizeof (evalbuf));-
409-
410 if (validp)
validpDescription
TRUEevaluated 209 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-209
411 *validp = 0;
executed 209 times by 1 test: *validp = 0;
Executed by:
  • Self test
209
412 return (0);
executed 209 times by 1 test: return (0);
Executed by:
  • Self test
209
413 }-
414-
415 val = subexpr (expr);-
416-
417 if (validp)
validpDescription
TRUEevaluated 7256272 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-7256272
418 *validp = 1;
executed 7256272 times by 1 test: *validp = 1;
Executed by:
  • Self test
7256272
419-
420 FASTCOPY (oevalbuf, evalbuf, sizeof (evalbuf));-
421-
422 return (val);
executed 7256272 times by 1 test: return (val);
Executed by:
  • Self test
7256272
423}-
424-
425static intmax_t-
426subexpr (expr)-
427 char *expr;-
428{-
429 intmax_t val;-
430 char *p;-
431-
432 for (p = expr; p && *p && cr_whitespace (*p); p++)
pDescription
TRUEevaluated 14516482 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 16 times by 1 test
Evaluated by:
  • Self test
*pDescription
TRUEevaluated 14516455 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 27 times by 1 test
Evaluated by:
  • Self test
((*p) == ' ')Description
TRUEevaluated 8346 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 14508109 times by 1 test
Evaluated by:
  • Self test
((*p) == '\t')Description
TRUEnever evaluated
FALSEevaluated 14508109 times by 1 test
Evaluated by:
  • Self test
((*p) == '\n')Description
TRUEnever evaluated
FALSEevaluated 14508109 times by 1 test
Evaluated by:
  • Self test
0-14516482
433 ;
executed 8346 times by 1 test: ;
Executed by:
  • Self test
8346
434-
435 if (p == NULL || *p == '\0')
p == ((void *)0)Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 14508136 times by 1 test
Evaluated by:
  • Self test
*p == '\0'Description
TRUEevaluated 27 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 14508109 times by 1 test
Evaluated by:
  • Self test
16-14508136
436 return (0);
executed 43 times by 1 test: return (0);
Executed by:
  • Self test
43
437-
438 pushexp ();-
439 expression = savestring (expr);-
440 tp = expression;-
441-
442 curtok = lasttok = 0;-
443 tokstr = (char *)NULL;-
444 tokval = 0;-
445 init_lvalue (&curlval);-
446 lastlval = curlval;-
447-
448 readtok ();-
449-
450 val = EXP_HIGHEST ();-
451-
452 if (curtok != 0)
curtok != 0Description
TRUEevaluated 15 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 14507889 times by 1 test
Evaluated by:
  • Self test
15-14507889
453 evalerror (_("syntax error in expression"));
executed 15 times by 1 test: evalerror ( dcgettext (((void *)0), "syntax error in expression" , 5) );
Executed by:
  • Self test
15
454-
455 FREE (tokstr);
executed 736643 times by 1 test: sh_xfree((tokstr), "expr.c", 455);
Executed by:
  • Self test
tokstrDescription
TRUEevaluated 736643 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 13771246 times by 1 test
Evaluated by:
  • Self test
736643-13771246
456 FREE (expression);
executed 14507889 times by 1 test: sh_xfree((expression), "expr.c", 456);
Executed by:
  • Self test
expressionDescription
TRUEevaluated 14507889 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-14507889
457-
458 popexp ();-
459-
460 return val;
executed 14507889 times by 1 test: return val;
Executed by:
  • Self test
14507889
461}-
462-
463static intmax_t-
464expcomma ()-
465{-
466 register intmax_t value;-
467-
468 value = expassign ();-
469 while (curtok == COMMA)
curtok == ','Description
TRUEevaluated 39613 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 14528747 times by 1 test
Evaluated by:
  • Self test
39613-14528747
470 {-
471 readtok ();-
472 value = expassign ();-
473 }
executed 39613 times by 1 test: end of block
Executed by:
  • Self test
39613
474-
475 return value;
executed 14528747 times by 1 test: return value;
Executed by:
  • Self test
14528747
476}-
477 -
478static intmax_t-
479expassign ()-
480{-
481 register intmax_t value;-
482 char *lhs, *rhs;-
483 arrayind_t lind;-
484#if defined (HAVE_IMAXDIV)-
485 imaxdiv_t idiv;-
486#endif-
487-
488 value = expcond ();-
489 if (curtok == EQ || curtok == OP_ASSIGN)
curtok == '='Description
TRUEevaluated 2636 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21074228 times by 1 test
Evaluated by:
  • Self test
curtok == 11Description
TRUEevaluated 6505866 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 14568362 times by 1 test
Evaluated by:
  • Self test
2636-21074228
490 {-
491 int special, op;-
492 intmax_t lvalue;-
493-
494 special = curtok == OP_ASSIGN;-
495-
496 if (lasttok != STR)
lasttok != 5Description
TRUEevaluated 52 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6508450 times by 1 test
Evaluated by:
  • Self test
52-6508450
497 evalerror (_("attempted assignment to non-variable"));
executed 52 times by 1 test: evalerror ( dcgettext (((void *)0), "attempted assignment to non-variable" , 5) );
Executed by:
  • Self test
52
498-
499 if (special)
specialDescription
TRUEevaluated 6505858 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2592 times by 1 test
Evaluated by:
  • Self test
2592-6505858
500 {-
501 op = assigntok; /* a OP= b */-
502 lvalue = value;-
503 }
executed 6505858 times by 1 test: end of block
Executed by:
  • Self test
6505858
504-
505 if (tokstr == 0)
tokstr == 0Description
TRUEnever evaluated
FALSEevaluated 6508450 times by 1 test
Evaluated by:
  • Self test
0-6508450
506 evalerror (_("syntax error in variable assignment"));
never executed: evalerror ( dcgettext (((void *)0), "syntax error in variable assignment" , 5) );
0
507-
508 /* XXX - watch out for pointer aliasing issues here */-
509 lhs = savestring (tokstr);-
510 /* save ind in case rhs is string var and evaluation overwrites it */-
511 lind = curlval.ind;-
512 readtok ();-
513 value = expassign ();-
514-
515 if (special)
specialDescription
TRUEevaluated 6505842 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2584 times by 1 test
Evaluated by:
  • Self test
2584-6505842
516 {-
517 if ((op == DIV || op == MOD) && value == 0)
op == '/'Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6505832 times by 1 test
Evaluated by:
  • Self test
op == '%'Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6505821 times by 1 test
Evaluated by:
  • Self test
value == 0Description
TRUEnever evaluated
FALSEevaluated 21 times by 1 test
Evaluated by:
  • Self test
0-6505832
518 {-
519 if (noeval == 0)
noeval == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
520 evalerror (_("division by 0"));
never executed: evalerror ( dcgettext (((void *)0), "division by 0" , 5) );
0
521 else-
522 value = 1;
never executed: value = 1;
0
523 }-
524-
525 switch (op)-
526 {-
527 case MUL:
executed 19819 times by 1 test: case '*':
Executed by:
  • Self test
19819
528 lvalue *= value;-
529 break;
executed 19819 times by 1 test: break;
Executed by:
  • Self test
19819
530 case DIV:
executed 10 times by 1 test: case '/':
Executed by:
  • Self test
10
531 case MOD:
executed 11 times by 1 test: case '%':
Executed by:
  • Self test
11
532 if (lvalue == INTMAX_MIN && value == -1)
lvalue == (-92...854775807L -1)Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 17 times by 1 test
Evaluated by:
  • Self test
value == -1Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-17
533 lvalue = (op == DIV) ? INTMAX_MIN : 0;
executed 4 times by 1 test: lvalue = (op == '/') ? (-9223372036854775807L -1) : 0;
Executed by:
  • Self test
(op == '/')Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
2-4
534 else-
535#if HAVE_IMAXDIV-
536 {-
537 idiv = imaxdiv (lvalue, value);-
538 lvalue = (op == DIV) ? idiv.quot : idiv.rem;
(op == '/')Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
8-9
539 }
executed 17 times by 1 test: end of block
Executed by:
  • Self test
17
540#else-
541 lvalue = (op == DIV) ? lvalue / value : lvalue % value;-
542#endif-
543 break;
executed 21 times by 1 test: break;
Executed by:
  • Self test
21
544 case PLUS:
executed 6485953 times by 1 test: case '+':
Executed by:
  • Self test
6485953
545 lvalue += value;-
546 break;
executed 6485953 times by 1 test: break;
Executed by:
  • Self test
6485953
547 case MINUS:
executed 9 times by 1 test: case '-':
Executed by:
  • Self test
9
548 lvalue -= value;-
549 break;
executed 9 times by 1 test: break;
Executed by:
  • Self test
9
550 case LSH:
executed 16 times by 1 test: case 9:
Executed by:
  • Self test
16
551 lvalue <<= value;-
552 break;
executed 16 times by 1 test: break;
Executed by:
  • Self test
16
553 case RSH:
executed 8 times by 1 test: case 10:
Executed by:
  • Self test
8
554 lvalue >>= value;-
555 break;
executed 8 times by 1 test: break;
Executed by:
  • Self test
8
556 case BAND:
executed 8 times by 1 test: case '&':
Executed by:
  • Self test
8
557 lvalue &= value;-
558 break;
executed 8 times by 1 test: break;
Executed by:
  • Self test
8
559 case BOR:
executed 8 times by 1 test: case '|':
Executed by:
  • Self test
8
560 lvalue |= value;-
561 break;
executed 8 times by 1 test: break;
Executed by:
  • Self test
8
562 case BXOR:
never executed: case '^':
0
563 lvalue ^= value;-
564 break;
never executed: break;
0
565 default:
never executed: default:
0
566 free (lhs);-
567 evalerror (_("bug: bad expassign token"));-
568 break;
never executed: break;
0
569 }-
570 value = lvalue;-
571 }
executed 6505842 times by 1 test: end of block
Executed by:
  • Self test
6505842
572-
573 rhs = itos (value);-
574 if (noeval == 0)
noeval == 0Description
TRUEevaluated 6490673 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 17753 times by 1 test
Evaluated by:
  • Self test
17753-6490673
575 {-
576#if defined (ARRAY_VARS)-
577 if (lind != -1)
lind != -1Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6490669 times by 1 test
Evaluated by:
  • Self test
4-6490669
578 expr_bind_array_element (lhs, lind, rhs);
executed 4 times by 1 test: expr_bind_array_element (lhs, lind, rhs);
Executed by:
  • Self test
4
579 else-
580#endif-
581 expr_bind_variable (lhs, rhs);
executed 6490669 times by 1 test: expr_bind_variable (lhs, rhs);
Executed by:
  • Self test
6490669
582 }-
583 if (curlval.tokstr && curlval.tokstr == tokstr)
curlval.tokstrDescription
TRUEevaluated 6488134 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 20290 times by 1 test
Evaluated by:
  • Self test
curlval.tokstr == tokstrDescription
TRUEevaluated 6488134 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-6488134
584 init_lvalue (&curlval);
executed 6488134 times by 1 test: init_lvalue (&curlval);
Executed by:
  • Self test
6488134
585-
586 free (rhs);-
587 free (lhs);-
588 FREE (tokstr);
executed 6507816 times by 1 test: sh_xfree((tokstr), "expr.c", 588);
Executed by:
  • Self test
tokstrDescription
TRUEevaluated 6507816 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 608 times by 1 test
Evaluated by:
  • Self test
608-6507816
589 tokstr = (char *)NULL; /* For freeing on errors. */-
590 }
executed 6508424 times by 1 test: end of block
Executed by:
  • Self test
6508424
591-
592 return (value);
executed 21076786 times by 1 test: return (value);
Executed by:
  • Self test
21076786
593}-
594-
595/* Conditional expression (expr?expr:expr) */-
596static intmax_t-
597expcond ()-
598{-
599 intmax_t cval, val1, val2, rval;-
600 int set_noeval;-
601-
602 set_noeval = 0;-
603 rval = cval = explor ();-
604 if (curtok == QUES) /* found conditional expr */
curtok == '?'Description
TRUEevaluated 240 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21076864 times by 1 test
Evaluated by:
  • Self test
240-21076864
605 {-
606 if (cval == 0)
cval == 0Description
TRUEevaluated 68 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 172 times by 1 test
Evaluated by:
  • Self test
68-172
607 {-
608 set_noeval = 1;-
609 noeval++;-
610 }
executed 68 times by 1 test: end of block
Executed by:
  • Self test
68
611-
612 readtok ();-
613 if (curtok == 0 || curtok == COL)
curtok == 0Description
TRUEnever evaluated
FALSEevaluated 240 times by 1 test
Evaluated by:
  • Self test
curtok == ':'Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 234 times by 1 test
Evaluated by:
  • Self test
0-240
614 evalerror (_("expression expected"));
executed 6 times by 1 test: evalerror ( dcgettext (((void *)0), "expression expected" , 5) );
Executed by:
  • Self test
6
615-
616 val1 = EXP_HIGHEST ();-
617-
618 if (set_noeval)
set_noevalDescription
TRUEevaluated 68 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 166 times by 1 test
Evaluated by:
  • Self test
68-166
619 noeval--;
executed 68 times by 1 test: noeval--;
Executed by:
  • Self test
68
620 if (curtok != COL)
curtok != ':'Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 228 times by 1 test
Evaluated by:
  • Self test
6-228
621 evalerror (_("`:' expected for conditional expression"));
executed 6 times by 1 test: evalerror ( dcgettext (((void *)0), "`:' expected for conditional expression" , 5) );
Executed by:
  • Self test
6
622-
623 set_noeval = 0;-
624 if (cval)
cvalDescription
TRUEevaluated 160 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 68 times by 1 test
Evaluated by:
  • Self test
68-160
625 {-
626 set_noeval = 1;-
627 noeval++;-
628 }
executed 160 times by 1 test: end of block
Executed by:
  • Self test
160
629-
630 readtok ();-
631 if (curtok == 0)
curtok == 0Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 222 times by 1 test
Evaluated by:
  • Self test
6-222
632 evalerror (_("expression expected"));
executed 6 times by 1 test: evalerror ( dcgettext (((void *)0), "expression expected" , 5) );
Executed by:
  • Self test
6
633 val2 = expcond ();-
634-
635 if (set_noeval)
set_noevalDescription
TRUEevaluated 154 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 68 times by 1 test
Evaluated by:
  • Self test
68-154
636 noeval--;
executed 154 times by 1 test: noeval--;
Executed by:
  • Self test
154
637 rval = cval ? val1 : val2;
cvalDescription
TRUEevaluated 154 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 68 times by 1 test
Evaluated by:
  • Self test
68-154
638 lasttok = COND;-
639 }
executed 222 times by 1 test: end of block
Executed by:
  • Self test
222
640 return rval;
executed 21077086 times by 1 test: return rval;
Executed by:
  • Self test
21077086
641}-
642-
643/* Logical OR. */-
644static intmax_t-
645explor ()-
646{-
647 register intmax_t val1, val2;-
648 int set_noeval;-
649-
650 val1 = expland ();-
651-
652 while (curtok == LOR)
curtok == 8Description
TRUEevaluated 19837 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21077104 times by 1 test
Evaluated by:
  • Self test
19837-21077104
653 {-
654 set_noeval = 0;-
655 if (val1 != 0)
val1 != 0Description
TRUEevaluated 17725 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2112 times by 1 test
Evaluated by:
  • Self test
2112-17725
656 {-
657 noeval++;-
658 set_noeval = 1;-
659 }
executed 17725 times by 1 test: end of block
Executed by:
  • Self test
17725
660 readtok ();-
661 val2 = expland ();-
662 if (set_noeval)
set_noevalDescription
TRUEevaluated 17725 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2112 times by 1 test
Evaluated by:
  • Self test
2112-17725
663 noeval--;
executed 17725 times by 1 test: noeval--;
Executed by:
  • Self test
17725
664 val1 = val1 || val2;
val1Description
TRUEevaluated 17725 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2112 times by 1 test
Evaluated by:
  • Self test
val2Description
TRUEevaluated 2010 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 102 times by 1 test
Evaluated by:
  • Self test
102-17725
665 lasttok = LOR;-
666 }
executed 19837 times by 1 test: end of block
Executed by:
  • Self test
19837
667-
668 return (val1);
executed 21077104 times by 1 test: return (val1);
Executed by:
  • Self test
21077104
669}-
670-
671/* Logical AND. */-
672static intmax_t-
673expland ()-
674{-
675 register intmax_t val1, val2;-
676 int set_noeval;-
677-
678 val1 = expbor ();-
679-
680 while (curtok == LAND)
curtok == 7Description
TRUEevaluated 65 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21096941 times by 1 test
Evaluated by:
  • Self test
65-21096941
681 {-
682 set_noeval = 0;-
683 if (val1 == 0)
val1 == 0Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 41 times by 1 test
Evaluated by:
  • Self test
24-41
684 {-
685 set_noeval = 1;-
686 noeval++;-
687 }
executed 24 times by 1 test: end of block
Executed by:
  • Self test
24
688 readtok ();-
689 val2 = expbor ();-
690 if (set_noeval)
set_noevalDescription
TRUEevaluated 24 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 41 times by 1 test
Evaluated by:
  • Self test
24-41
691 noeval--;
executed 24 times by 1 test: noeval--;
Executed by:
  • Self test
24
692 val1 = val1 && val2;
val1Description
TRUEevaluated 41 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 24 times by 1 test
Evaluated by:
  • Self test
val2Description
TRUEevaluated 19 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 22 times by 1 test
Evaluated by:
  • Self test
19-41
693 lasttok = LAND;-
694 }
executed 65 times by 1 test: end of block
Executed by:
  • Self test
65
695-
696 return (val1);
executed 21096941 times by 1 test: return (val1);
Executed by:
  • Self test
21096941
697}-
698-
699/* Bitwise OR. */-
700static intmax_t-
701expbor ()-
702{-
703 register intmax_t val1, val2;-
704-
705 val1 = expbxor ();-
706-
707 while (curtok == BOR)
curtok == '|'Description
TRUEevaluated 33 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21097006 times by 1 test
Evaluated by:
  • Self test
33-21097006
708 {-
709 readtok ();-
710 val2 = expbxor ();-
711 val1 = val1 | val2;-
712 lasttok = NUM;-
713 }
executed 33 times by 1 test: end of block
Executed by:
  • Self test
33
714-
715 return (val1);
executed 21097006 times by 1 test: return (val1);
Executed by:
  • Self test
21097006
716}-
717-
718/* Bitwise XOR. */-
719static intmax_t-
720expbxor ()-
721{-
722 register intmax_t val1, val2;-
723-
724 val1 = expband ();-
725-
726 while (curtok == BXOR)
curtok == '^'Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21097039 times by 1 test
Evaluated by:
  • Self test
8-21097039
727 {-
728 readtok ();-
729 val2 = expband ();-
730 val1 = val1 ^ val2;-
731 lasttok = NUM;-
732 }
executed 8 times by 1 test: end of block
Executed by:
  • Self test
8
733-
734 return (val1);
executed 21097039 times by 1 test: return (val1);
Executed by:
  • Self test
21097039
735}-
736-
737/* Bitwise AND. */-
738static intmax_t-
739expband ()-
740{-
741 register intmax_t val1, val2;-
742-
743 val1 = exp5 ();-
744-
745 while (curtok == BAND)
curtok == '&'Description
TRUEevaluated 26 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21097047 times by 1 test
Evaluated by:
  • Self test
26-21097047
746 {-
747 readtok ();-
748 val2 = exp5 ();-
749 val1 = val1 & val2;-
750 lasttok = NUM;-
751 }
executed 26 times by 1 test: end of block
Executed by:
  • Self test
26
752-
753 return (val1);
executed 21097047 times by 1 test: return (val1);
Executed by:
  • Self test
21097047
754}-
755-
756static intmax_t-
757exp5 ()-
758{-
759 register intmax_t val1, val2;-
760-
761 val1 = exp4 ();-
762-
763 while ((curtok == EQEQ) || (curtok == NEQ))
(curtok == 1)Description
TRUEevaluated 47 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21097083 times by 1 test
Evaluated by:
  • Self test
(curtok == 2)Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21097073 times by 1 test
Evaluated by:
  • Self test
10-21097083
764 {-
765 int op = curtok;-
766-
767 readtok ();-
768 val2 = exp4 ();-
769 if (op == EQEQ)
op == 1Description
TRUEevaluated 47 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 10 times by 1 test
Evaluated by:
  • Self test
10-47
770 val1 = (val1 == val2);
executed 47 times by 1 test: val1 = (val1 == val2);
Executed by:
  • Self test
47
771 else if (op == NEQ)
op == 2Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-10
772 val1 = (val1 != val2);
executed 10 times by 1 test: val1 = (val1 != val2);
Executed by:
  • Self test
10
773 lasttok = NUM;-
774 }
executed 57 times by 1 test: end of block
Executed by:
  • Self test
57
775 return (val1);
executed 21097073 times by 1 test: return (val1);
Executed by:
  • Self test
21097073
776}-
777-
778static intmax_t-
779exp4 ()-
780{-
781 register intmax_t val1, val2;-
782-
783 val1 = expshift ();-
784 while ((curtok == LEQ) ||
(curtok == 3)Description
TRUEevaluated 19827 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21117640 times by 1 test
Evaluated by:
  • Self test
19827-21117640
785 (curtok == GEQ) ||
(curtok == 4)Description
TRUEevaluated 1625 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21116015 times by 1 test
Evaluated by:
  • Self test
1625-21116015
786 (curtok == LT) ||
(curtok == '<')Description
TRUEevaluated 16589 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21099426 times by 1 test
Evaluated by:
  • Self test
16589-21099426
787 (curtok == GT))
(curtok == '>')Description
TRUEevaluated 2296 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21097130 times by 1 test
Evaluated by:
  • Self test
2296-21097130
788 {-
789 int op = curtok;-
790-
791 readtok ();-
792 val2 = expshift ();-
793-
794 if (op == LEQ)
op == 3Description
TRUEevaluated 19827 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 20510 times by 1 test
Evaluated by:
  • Self test
19827-20510
795 val1 = val1 <= val2;
executed 19827 times by 1 test: val1 = val1 <= val2;
Executed by:
  • Self test
19827
796 else if (op == GEQ)
op == 4Description
TRUEevaluated 1625 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 18885 times by 1 test
Evaluated by:
  • Self test
1625-18885
797 val1 = val1 >= val2;
executed 1625 times by 1 test: val1 = val1 >= val2;
Executed by:
  • Self test
1625
798 else if (op == LT)
op == '<'Description
TRUEevaluated 16589 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2296 times by 1 test
Evaluated by:
  • Self test
2296-16589
799 val1 = val1 < val2;
executed 16589 times by 1 test: val1 = val1 < val2;
Executed by:
  • Self test
16589
800 else /* (op == GT) */-
801 val1 = val1 > val2;
executed 2296 times by 1 test: val1 = val1 > val2;
Executed by:
  • Self test
2296
802 lasttok = NUM;-
803 }
executed 40337 times by 1 test: end of block
Executed by:
  • Self test
40337
804 return (val1);
executed 21097130 times by 1 test: return (val1);
Executed by:
  • Self test
21097130
805}-
806-
807/* Left and right shifts. */-
808static intmax_t-
809expshift ()-
810{-
811 register intmax_t val1, val2;-
812-
813 val1 = exp3 ();-
814-
815 while ((curtok == LSH) || (curtok == RSH))
(curtok == 9)Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21137475 times by 1 test
Evaluated by:
  • Self test
(curtok == 10)Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21137467 times by 1 test
Evaluated by:
  • Self test
8-21137475
816 {-
817 int op = curtok;-
818-
819 readtok ();-
820 val2 = exp3 ();-
821-
822 if (op == LSH)
op == 9Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
8-9
823 val1 = val1 << val2;
executed 9 times by 1 test: val1 = val1 << val2;
Executed by:
  • Self test
9
824 else-
825 val1 = val1 >> val2;
executed 8 times by 1 test: val1 = val1 >> val2;
Executed by:
  • Self test
8
826 lasttok = NUM;-
827 }
executed 17 times by 1 test: end of block
Executed by:
  • Self test
17
828-
829 return (val1);
executed 21137467 times by 1 test: return (val1);
Executed by:
  • Self test
21137467
830}-
831-
832static intmax_t-
833exp3 ()-
834{-
835 register intmax_t val1, val2;-
836-
837 val1 = exp2 ();-
838-
839 while ((curtok == PLUS) || (curtok == MINUS))
(curtok == '+')Description
TRUEevaluated 30855 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21137729 times by 1 test
Evaluated by:
  • Self test
(curtok == '-')Description
TRUEevaluated 245 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21137484 times by 1 test
Evaluated by:
  • Self test
245-21137729
840 {-
841 int op = curtok;-
842-
843 readtok ();-
844 val2 = exp2 ();-
845-
846 if (op == PLUS)
op == '+'Description
TRUEevaluated 30829 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 237 times by 1 test
Evaluated by:
  • Self test
237-30829
847 val1 += val2;
executed 30829 times by 1 test: val1 += val2;
Executed by:
  • Self test
30829
848 else if (op == MINUS)
op == '-'Description
TRUEevaluated 237 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-237
849 val1 -= val2;
executed 237 times by 1 test: val1 -= val2;
Executed by:
  • Self test
237
850 lasttok = NUM;-
851 }
executed 31066 times by 1 test: end of block
Executed by:
  • Self test
31066
852 return (val1);
executed 21137484 times by 1 test: return (val1);
Executed by:
  • Self test
21137484
853}-
854-
855static intmax_t-
856exp2 ()-
857{-
858 register intmax_t val1, val2;-
859#if defined (HAVE_IMAXDIV)-
860 imaxdiv_t idiv;-
861#endif-
862-
863 val1 = exppower ();-
864-
865 while ((curtok == MUL) ||
(curtok == '*')Description
TRUEevaluated 29 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21208682 times by 1 test
Evaluated by:
  • Self test
29-21208682
866 (curtok == DIV) ||
(curtok == '/')Description
TRUEevaluated 60 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21208622 times by 1 test
Evaluated by:
  • Self test
60-21208622
867 (curtok == MOD))
(curtok == '%')Description
TRUEevaluated 40038 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21168584 times by 1 test
Evaluated by:
  • Self test
40038-21168584
868 {-
869 int op = curtok;-
870 char *stp, *sltp;-
871-
872 stp = tp;-
873 readtok ();-
874-
875 val2 = exppower ();-
876-
877 /* Handle division by 0 and twos-complement arithmetic overflow */-
878 if (((op == DIV) || (op == MOD)) && (val2 == 0))
(op == '/')Description
TRUEevaluated 60 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 40067 times by 1 test
Evaluated by:
  • Self test
(op == '%')Description
TRUEevaluated 40038 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 29 times by 1 test
Evaluated by:
  • Self test
(val2 == 0)Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 40090 times by 1 test
Evaluated by:
  • Self test
8-40090
879 {-
880 if (noeval == 0)
noeval == 0Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-8
881 {-
882 sltp = lasttp;-
883 lasttp = stp;-
884 while (lasttp && *lasttp && whitespace (*lasttp))
lasttpDescription
TRUEevaluated 16 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
*lasttpDescription
TRUEevaluated 16 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
((*lasttp) == ' ')Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
((*lasttp) == '\t')Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
0-16
885 lasttp++;
executed 8 times by 1 test: lasttp++;
Executed by:
  • Self test
8
886 evalerror (_("division by 0"));-
887 lasttp = sltp;-
888 }
never executed: end of block
0
889 else-
890 val2 = 1;
never executed: val2 = 1;
0
891 }-
892 else if (op == MOD && val1 == INTMAX_MIN && val2 == -1)
op == '%'Description
TRUEevaluated 40038 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 81 times by 1 test
Evaluated by:
  • Self test
val1 == (-9223...854775807L -1)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 40036 times by 1 test
Evaluated by:
  • Self test
val2 == -1Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-40038
893 {-
894 val1 = 0;-
895 continue;
executed 2 times by 1 test: continue;
Executed by:
  • Self test
2
896 }-
897 else if (op == DIV && val1 == INTMAX_MIN && val2 == -1)
op == '/'Description
TRUEevaluated 52 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 40065 times by 1 test
Evaluated by:
  • Self test
val1 == (-9223...854775807L -1)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 50 times by 1 test
Evaluated by:
  • Self test
val2 == -1Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-40065
898 val2 = 1;
executed 2 times by 1 test: val2 = 1;
Executed by:
  • Self test
2
899-
900 if (op == MUL)
op == '*'Description
TRUEevaluated 29 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 40088 times by 1 test
Evaluated by:
  • Self test
29-40088
901 val1 *= val2;
executed 29 times by 1 test: val1 *= val2;
Executed by:
  • Self test
29
902 else if (op == DIV || op == MOD)
op == '/'Description
TRUEevaluated 52 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 40036 times by 1 test
Evaluated by:
  • Self test
op == '%'Description
TRUEevaluated 40036 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-40036
903#if defined (HAVE_IMAXDIV)-
904 {-
905 idiv = imaxdiv (val1, val2);-
906 val1 = (op == DIV) ? idiv.quot : idiv.rem;
(op == '/')Description
TRUEevaluated 52 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 40036 times by 1 test
Evaluated by:
  • Self test
52-40036
907 }
executed 40088 times by 1 test: end of block
Executed by:
  • Self test
40088
908#else-
909 val1 = (op == DIV) ? val1 / val2 : val1 % val2;-
910#endif-
911 lasttok = NUM;-
912 }
executed 40117 times by 1 test: end of block
Executed by:
  • Self test
40117
913 return (val1);
executed 21168584 times by 1 test: return (val1);
Executed by:
  • Self test
21168584
914}-
915-
916static intmax_t-
917ipow (base, exp)-
918 intmax_t base, exp;-
919{-
920 intmax_t result;-
921-
922 result = 1;-
923 while (exp)
expDescription
TRUEevaluated 126 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 27 times by 1 test
Evaluated by:
  • Self test
27-126
924 {-
925 if (exp & 1)
exp & 1Description
TRUEevaluated 102 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 24 times by 1 test
Evaluated by:
  • Self test
24-102
926 result *= base;
executed 102 times by 1 test: result *= base;
Executed by:
  • Self test
102
927 exp >>= 1;-
928 base *= base;-
929 }
executed 126 times by 1 test: end of block
Executed by:
  • Self test
126
930 return result;
executed 27 times by 1 test: return result;
Executed by:
  • Self test
27
931}-
932-
933static intmax_t-
934exppower ()-
935{-
936 register intmax_t val1, val2, c;-
937-
938 val1 = exp1 ();-
939 while (curtok == POWER)
curtok == 13Description
TRUEevaluated 33 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21208746 times by 1 test
Evaluated by:
  • Self test
33-21208746
940 {-
941 readtok ();-
942 val2 = exppower (); /* exponentiation is right-associative */-
943 lasttok = NUM;-
944 if (val2 == 0)
val2 == 0Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 27 times by 1 test
Evaluated by:
  • Self test
6-27
945 return (1);
executed 6 times by 1 test: return (1);
Executed by:
  • Self test
6
946 if (val2 < 0)
val2 < 0Description
TRUEnever evaluated
FALSEevaluated 27 times by 1 test
Evaluated by:
  • Self test
0-27
947 evalerror (_("exponent less than 0"));
never executed: evalerror ( dcgettext (((void *)0), "exponent less than 0" , 5) );
0
948 val1 = ipow (val1, val2);-
949 }
executed 27 times by 1 test: end of block
Executed by:
  • Self test
27
950 return (val1);
executed 21208746 times by 1 test: return (val1);
Executed by:
  • Self test
21208746
951}-
952-
953static intmax_t-
954exp1 ()-
955{-
956 register intmax_t val;-
957-
958 if (curtok == NOT)
curtok == '!'Description
TRUEevaluated 15 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21238917 times by 1 test
Evaluated by:
  • Self test
15-21238917
959 {-
960 readtok ();-
961 val = !exp1 ();-
962 lasttok = NUM;-
963 }
executed 15 times by 1 test: end of block
Executed by:
  • Self test
15
964 else if (curtok == BNOT)
curtok == '~'Description
TRUEevaluated 18 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21238899 times by 1 test
Evaluated by:
  • Self test
18-21238899
965 {-
966 readtok ();-
967 val = ~exp1 ();-
968 lasttok = NUM;-
969 }
executed 17 times by 1 test: end of block
Executed by:
  • Self test
17
970 else if (curtok == MINUS)
curtok == '-'Description
TRUEevaluated 30027 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21208872 times by 1 test
Evaluated by:
  • Self test
30027-21208872
971 {-
972 readtok ();-
973 val = - exp1 ();-
974 lasttok = NUM;-
975 }
executed 30015 times by 1 test: end of block
Executed by:
  • Self test
30015
976 else if (curtok == PLUS)
curtok == '+'Description
TRUEevaluated 79 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21208793 times by 1 test
Evaluated by:
  • Self test
79-21208793
977 {-
978 readtok ();-
979 val = exp1 ();-
980 lasttok = NUM;-
981 }
executed 73 times by 1 test: end of block
Executed by:
  • Self test
73
982 else-
983 val = exp0 ();
executed 21208793 times by 1 test: val = exp0 ();
Executed by:
  • Self test
21208793
984-
985 return (val);
executed 21238872 times by 1 test: return (val);
Executed by:
  • Self test
21238872
986}-
987-
988static intmax_t-
989exp0 ()-
990{-
991 register intmax_t val = 0, v2;-
992 char *vincdec;-
993 int stok;-
994 EXPR_CONTEXT ec;-
995-
996 /* XXX - might need additional logic here to decide whether or not-
997 pre-increment or pre-decrement is legal at this point. */-
998 if (curtok == PREINC || curtok == PREDEC)
curtok == 14Description
TRUEevaluated 32 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21208761 times by 1 test
Evaluated by:
  • Self test
curtok == 15Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21208745 times by 1 test
Evaluated by:
  • Self test
16-21208761
999 {-
1000 stok = lasttok = curtok;-
1001 readtok ();-
1002 if (curtok != STR)
curtok != 5Description
TRUEnever evaluated
FALSEevaluated 48 times by 1 test
Evaluated by:
  • Self test
0-48
1003 /* readtok() catches this */-
1004 evalerror (_("identifier expected after pre-increment or pre-decrement"));
never executed: evalerror ( dcgettext (((void *)0), "identifier expected after pre-increment or pre-decrement" , 5) );
0
1005-
1006 v2 = tokval + ((stok == PREINC) ? 1 : -1);
(stok == 14)Description
TRUEevaluated 32 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 16 times by 1 test
Evaluated by:
  • Self test
16-32
1007 vincdec = itos (v2);-
1008 if (noeval == 0)
noeval == 0Description
TRUEevaluated 48 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-48
1009 {-
1010#if defined (ARRAY_VARS)-
1011 if (curlval.ind != -1)
curlval.ind != -1Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 45 times by 1 test
Evaluated by:
  • Self test
3-45
1012 expr_bind_array_element (curlval.tokstr, curlval.ind, vincdec);
executed 3 times by 1 test: expr_bind_array_element (curlval.tokstr, curlval.ind, vincdec);
Executed by:
  • Self test
3
1013 else-
1014#endif-
1015 expr_bind_variable (tokstr, vincdec);
executed 45 times by 1 test: expr_bind_variable (tokstr, vincdec);
Executed by:
  • Self test
45
1016 }-
1017 free (vincdec);-
1018 val = v2;-
1019-
1020 curtok = NUM; /* make sure --x=7 is flagged as an error */-
1021 readtok ();-
1022 }
executed 48 times by 1 test: end of block
Executed by:
  • Self test
48
1023 else if (curtok == LPAR)
curtok == '('Description
TRUEevaluated 20615 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21188130 times by 1 test
Evaluated by:
  • Self test
20615-21188130
1024 {-
1025 /* XXX - save curlval here? Or entire expression context? */-
1026 readtok ();-
1027 val = EXP_HIGHEST ();-
1028-
1029 if (curtok != RPAR) /* ( */
curtok != ')'Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 20601 times by 1 test
Evaluated by:
  • Self test
8-20601
1030 evalerror (_("missing `)'"));
executed 8 times by 1 test: evalerror ( dcgettext (((void *)0), "missing `)'" , 5) );
Executed by:
  • Self test
8
1031-
1032 /* Skip over closing paren. */-
1033 readtok ();-
1034 }
executed 20601 times by 1 test: end of block
Executed by:
  • Self test
20601
1035 else if ((curtok == NUM) || (curtok == STR))
(curtok == 6)Description
TRUEevaluated 13898301 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7289829 times by 1 test
Evaluated by:
  • Self test
(curtok == 5)Description
TRUEevaluated 7289803 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 26 times by 1 test
Evaluated by:
  • Self test
26-13898301
1036 {-
1037 val = tokval;-
1038 if (curtok == STR)
curtok == 5Description
TRUEevaluated 7289803 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 13898301 times by 1 test
Evaluated by:
  • Self test
7289803-13898301
1039 {-
1040 SAVETOK (&ec);-
1041 tokstr = (char *)NULL; /* keep it from being freed */-
1042 noeval = 1;-
1043 readtok ();-
1044 stok = curtok;-
1045-
1046 /* post-increment or post-decrement */-
1047 if (stok == POSTINC || stok == POSTDEC)
stok == 16Description
TRUEevaluated 48332 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7241471 times by 1 test
Evaluated by:
  • Self test
stok == 17Description
TRUEevaluated 661983 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6579488 times by 1 test
Evaluated by:
  • Self test
48332-7241471
1048 {-
1049 /* restore certain portions of EC */-
1050 tokstr = ec.tokstr;-
1051 noeval = ec.noeval;-
1052 curlval = ec.lval;-
1053 lasttok = STR; /* ec.curtok */-
1054-
1055 v2 = val + ((stok == POSTINC) ? 1 : -1);
(stok == 16)Description
TRUEevaluated 48332 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 661983 times by 1 test
Evaluated by:
  • Self test
48332-661983
1056 vincdec = itos (v2);-
1057 if (noeval == 0)
noeval == 0Description
TRUEevaluated 692627 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 17688 times by 1 test
Evaluated by:
  • Self test
17688-692627
1058 {-
1059#if defined (ARRAY_VARS)-
1060 if (curlval.ind != -1)
curlval.ind != -1Description
TRUEevaluated 10003 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 682624 times by 1 test
Evaluated by:
  • Self test
10003-682624
1061 expr_bind_array_element (curlval.tokstr, curlval.ind, vincdec);
executed 10003 times by 1 test: expr_bind_array_element (curlval.tokstr, curlval.ind, vincdec);
Executed by:
  • Self test
10003
1062 else-
1063#endif-
1064 expr_bind_variable (tokstr, vincdec);
executed 682624 times by 1 test: expr_bind_variable (tokstr, vincdec);
Executed by:
  • Self test
682624
1065 }-
1066 free (vincdec);-
1067 curtok = NUM; /* make sure x++=7 is flagged as an error */-
1068 }
executed 710314 times by 1 test: end of block
Executed by:
  • Self test
710314
1069 else-
1070 {-
1071 /* XXX - watch out for pointer aliasing issues here */-
1072 if (stok == STR) /* free new tokstr before old one is restored */
stok == 5Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6579479 times by 1 test
Evaluated by:
  • Self test
9-6579479
1073 FREE (tokstr);
executed 9 times by 1 test: sh_xfree((tokstr), "expr.c", 1073);
Executed by:
  • Self test
executed 9 times by 1 test: end of block
Executed by:
  • Self test
tokstrDescription
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-9
1074 RESTORETOK (&ec);-
1075 }
executed 6579488 times by 1 test: end of block
Executed by:
  • Self test
6579488
1076 }-
1077 -
1078 readtok ();-
1079 }
executed 21188103 times by 1 test: end of block
Executed by:
  • Self test
21188103
1080 else-
1081 evalerror (_("syntax error: operand expected"));
executed 26 times by 1 test: evalerror ( dcgettext (((void *)0), "syntax error: operand expected" , 5) );
Executed by:
  • Self test
26
1082-
1083 return (val);
executed 21208752 times by 1 test: return (val);
Executed by:
  • Self test
21208752
1084}-
1085-
1086static void-
1087init_lvalue (lv)-
1088 struct lvalue *lv;-
1089{-
1090 lv->tokstr = 0;-
1091 lv->tokvar = 0;-
1092 lv->tokval = lv->ind = -1;-
1093}
executed 21040922 times by 1 test: end of block
Executed by:
  • Self test
21040922
1094-
1095static struct lvalue *-
1096alloc_lvalue ()-
1097{-
1098 struct lvalue *lv;-
1099-
1100 lv = xmalloc (sizeof (struct lvalue));-
1101 init_lvalue (lv);-
1102 return (lv);
never executed: return (lv);
0
1103}-
1104-
1105static void-
1106free_lvalue (lv)-
1107 struct lvalue *lv;-
1108{-
1109 free (lv); /* should be inlined */-
1110}
never executed: end of block
0
1111-
1112static intmax_t-
1113expr_streval (tok, e, lvalue)-
1114 char *tok;-
1115 int e;-
1116 struct lvalue *lvalue;-
1117{-
1118 SHELL_VAR *v;-
1119 char *value;-
1120 intmax_t tval;-
1121 int initial_depth;-
1122#if defined (ARRAY_VARS)-
1123 arrayind_t ind;-
1124 int tflag, aflag;-
1125#endif-
1126-
1127/*itrace("expr_streval: %s: noeval = %d expanded=%d", tok, noeval, already_expanded);*/-
1128 /* If we are suppressing evaluation, just short-circuit here instead of-
1129 going through the rest of the evaluator. */-
1130 if (noeval)
noevalDescription
TRUEevaluated 35477 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7251807 times by 1 test
Evaluated by:
  • Self test
35477-7251807
1131 return (0);
executed 35477 times by 1 test: return (0);
Executed by:
  • Self test
35477
1132-
1133 initial_depth = expr_depth;-
1134-
1135#if defined (ARRAY_VARS)-
1136 tflag = assoc_expand_once && already_expanded; /* for a start */
assoc_expand_onceDescription
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7251800 times by 1 test
Evaluated by:
  • Self test
already_expandedDescription
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-7251800
1137#endif-
1138-
1139 /* [[[[[ */-
1140#if defined (ARRAY_VARS)-
1141 aflag = (tflag) ? AV_NOEXPAND : 0;
(tflag)Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7251800 times by 1 test
Evaluated by:
  • Self test
7-7251800
1142 v = (e == ']') ? array_variable_part (tok, tflag, (char **)0, (int *)0) : find_variable (tok);
(e == ']')Description
TRUEevaluated 10105 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7241702 times by 1 test
Evaluated by:
  • Self test
10105-7241702
1143#else-
1144 v = find_variable (tok);-
1145#endif-
1146-
1147 if ((v == 0 || invisible_p (v)) && unbound_vars_is_error)
v == 0Description
TRUEevaluated 105 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7251702 times by 1 test
Evaluated by:
  • Self test
((((v)->attrib... (0x0001000)))Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7251692 times by 1 test
Evaluated by:
  • Self test
unbound_vars_is_errorDescription
TRUEnever evaluated
FALSEevaluated 115 times by 1 test
Evaluated by:
  • Self test
0-7251702
1148 {-
1149#if defined (ARRAY_VARS)-
1150 value = (e == ']') ? array_variable_name (tok, tflag, (char **)0, (int *)0) : tok;
(e == ']')Description
TRUEnever evaluated
FALSEnever evaluated
0
1151#else-
1152 value = tok;-
1153#endif-
1154-
1155 last_command_exit_value = EXECUTION_FAILURE;-
1156 err_unboundvar (value);-
1157-
1158#if defined (ARRAY_VARS)-
1159 if (e == ']')
e == ']'Description
TRUEnever evaluated
FALSEnever evaluated
0
1160 FREE (value); /* array_variable_name returns new memory */
never executed: sh_xfree((value), "expr.c", 1160);
never executed: end of block
valueDescription
TRUEnever evaluated
FALSEnever evaluated
0
1161#endif-
1162-
1163 if (no_longjmp_on_fatal_error && interactive_shell)
no_longjmp_on_fatal_errorDescription
TRUEnever evaluated
FALSEnever evaluated
interactive_shellDescription
TRUEnever evaluated
FALSEnever evaluated
0
1164 sh_longjmp (evalbuf, 1);
never executed: siglongjmp((evalbuf), (1));
0
1165-
1166 if (interactive_shell)
interactive_shellDescription
TRUEnever evaluated
FALSEnever evaluated
0
1167 {-
1168 expr_unwind ();-
1169 top_level_cleanup ();-
1170 jump_to_top_level (DISCARD);-
1171 }
never executed: end of block
0
1172 else-
1173 jump_to_top_level (FORCE_EOF);
never executed: jump_to_top_level (1);
0
1174 }-
1175-
1176#if defined (ARRAY_VARS)-
1177 ind = -1;-
1178 /* If the second argument to get_array_value doesn't include AV_ALLOWALL,-
1179 we don't allow references like array[@]. In this case, get_array_value-
1180 is just like get_variable_value in that it does not return newly-allocated-
1181 memory or quote the results. AFLAG is set above and is either AV_NOEXPAND-
1182 or 0. */-
1183 value = (e == ']') ? get_array_value (tok, aflag, (int *)NULL, &ind) : get_variable_value (v);
(e == ']')Description
TRUEevaluated 10105 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7241702 times by 1 test
Evaluated by:
  • Self test
10105-7241702
1184#else-
1185 value = get_variable_value (v);-
1186#endif-
1187-
1188 if (expr_depth < initial_depth)
expr_depth < initial_depthDescription
TRUEnever evaluated
FALSEevaluated 7251803 times by 1 test
Evaluated by:
  • Self test
0-7251803
1189 {-
1190 if (no_longjmp_on_fatal_error && interactive_shell)
no_longjmp_on_fatal_errorDescription
TRUEnever evaluated
FALSEnever evaluated
interactive_shellDescription
TRUEnever evaluated
FALSEnever evaluated
0
1191 sh_longjmp (evalbuf, 1);
never executed: siglongjmp((evalbuf), (1));
0
1192 return (0);
never executed: return (0);
0
1193 }-
1194-
1195 tval = (value && *value) ? subexpr (value) : 0;
valueDescription
TRUEevaluated 7251666 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 137 times by 1 test
Evaluated by:
  • Self test
*valueDescription
TRUEevaluated 7251666 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-7251666
1196-
1197 if (lvalue)
lvalueDescription
TRUEevaluated 7251797 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-7251797
1198 {-
1199 lvalue->tokstr = tok; /* XXX */-
1200 lvalue->tokval = tval;-
1201 lvalue->tokvar = v; /* XXX */-
1202#if defined (ARRAY_VARS)-
1203 lvalue->ind = ind;-
1204#else-
1205 lvalue->ind = -1;-
1206#endif-
1207 }
executed 7251797 times by 1 test: end of block
Executed by:
  • Self test
7251797
1208 -
1209 return (tval);
executed 7251797 times by 1 test: return (tval);
Executed by:
  • Self test
7251797
1210}-
1211-
1212static int-
1213_is_multiop (c)-
1214 int c;-
1215{-
1216 switch (c)-
1217 {-
1218 case EQEQ:
never executed: case 1:
0
1219 case NEQ:
never executed: case 2:
0
1220 case LEQ:
never executed: case 3:
0
1221 case GEQ:
never executed: case 4:
0
1222 case LAND:
never executed: case 7:
0
1223 case LOR:
never executed: case 8:
0
1224 case LSH:
never executed: case 9:
0
1225 case RSH:
never executed: case 10:
0
1226 case OP_ASSIGN:
executed 16 times by 1 test: case 11:
Executed by:
  • Self test
16
1227 case COND:
never executed: case 12:
0
1228 case POWER:
never executed: case 13:
0
1229 case PREINC:
never executed: case 14:
0
1230 case PREDEC:
never executed: case 15:
0
1231 case POSTINC:
never executed: case 16:
0
1232 case POSTDEC:
never executed: case 17:
0
1233 return 1;
executed 16 times by 1 test: return 1;
Executed by:
  • Self test
16
1234 default:
executed 1 time by 1 test: default:
Executed by:
  • Self test
1
1235 return 0;
executed 1 time by 1 test: return 0;
Executed by:
  • Self test
1
1236 }-
1237}-
1238-
1239static int-
1240_is_arithop (c)-
1241 int c;-
1242{-
1243 switch (c)-
1244 {-
1245 case EQ:
executed 7860 times by 1 test: case '=':
Executed by:
  • Self test
7860
1246 case GT:
executed 6820 times by 1 test: case '>':
Executed by:
  • Self test
6820
1247 case LT:
executed 49615 times by 1 test: case '<':
Executed by:
  • Self test
49615
1248 case PLUS:
executed 31403 times by 1 test: case '+':
Executed by:
  • Self test
31403
1249 case MINUS:
executed 30325 times by 1 test: case '-':
Executed by:
  • Self test
30325
1250 case MUL:
executed 29 times by 1 test: case '*':
Executed by:
  • Self test
29
1251 case DIV:
executed 62 times by 1 test: case '/':
Executed by:
  • Self test
62
1252 case MOD:
executed 100077 times by 1 test: case '%':
Executed by:
  • Self test
100077
1253 case NOT:
executed 15 times by 1 test: case '!':
Executed by:
  • Self test
15
1254 case LPAR:
executed 20615 times by 1 test: case '(':
Executed by:
  • Self test
20615
1255 case RPAR:
executed 20657 times by 1 test: case ')':
Executed by:
  • Self test
20657
1256 case BAND:
executed 58 times by 1 test: case '&':
Executed by:
  • Self test
58
1257 case BOR:
executed 65 times by 1 test: case '|':
Executed by:
  • Self test
65
1258 case BXOR:
executed 8 times by 1 test: case '^':
Executed by:
  • Self test
8
1259 case BNOT:
executed 18 times by 1 test: case '~':
Executed by:
  • Self test
18
1260 return 1; /* operator tokens */
executed 267627 times by 1 test: return 1;
Executed by:
  • Self test
267627
1261 case QUES:
executed 360 times by 1 test: case '?':
Executed by:
  • Self test
360
1262 case COL:
executed 238 times by 1 test: case ':':
Executed by:
  • Self test
238
1263 case COMMA:
executed 39627 times by 1 test: case ',':
Executed by:
  • Self test
39627
1264 return 1; /* questionable */
executed 40225 times by 1 test: return 1;
Executed by:
  • Self test
40225
1265 default:
executed 65 times by 1 test: default:
Executed by:
  • Self test
65
1266 return 0; /* anything else is invalid */
executed 65 times by 1 test: return 0;
Executed by:
  • Self test
65
1267 }-
1268}-
1269-
1270/* Lexical analyzer/token reader for the expression evaluator. Reads the-
1271 next token and puts its value into curtok, while advancing past it.-
1272 Updates value of tp. May also set tokval (for number) or tokstr (for-
1273 string). */-
1274static void-
1275readtok ()-
1276{-
1277 register char *cp, *xp;-
1278 register unsigned char c, c1;-
1279 register int e;-
1280 struct lvalue lval;-
1281-
1282 /* Skip leading whitespace. */-
1283 cp = tp;-
1284 c = e = 0;-
1285 while (cp && (c = *cp) && (cr_whitespace (c)))
cpDescription
TRUEevaluated 57559084 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(c = *cp)Description
TRUEevaluated 43010907 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 14548177 times by 1 test
Evaluated by:
  • Self test
((c) == ' ')Description
TRUEevaluated 531554 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 42479353 times by 1 test
Evaluated by:
  • Self test
((c) == '\t')Description
TRUEnever evaluated
FALSEevaluated 42479353 times by 1 test
Evaluated by:
  • Self test
((c) == '\n')Description
TRUEnever evaluated
FALSEevaluated 42479353 times by 1 test
Evaluated by:
  • Self test
0-57559084
1286 cp++;
executed 531554 times by 1 test: cp++;
Executed by:
  • Self test
531554
1287-
1288 if (c)
cDescription
TRUEevaluated 42479353 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 14548177 times by 1 test
Evaluated by:
  • Self test
14548177-42479353
1289 cp++;
executed 42479353 times by 1 test: cp++;
Executed by:
  • Self test
42479353
1290-
1291 if (c == '\0')
c == '\0'Description
TRUEevaluated 14548177 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 42479353 times by 1 test
Evaluated by:
  • Self test
14548177-42479353
1292 {-
1293 lasttok = curtok;-
1294 curtok = 0;-
1295 tp = cp;-
1296 return;
executed 14548177 times by 1 test: return;
Executed by:
  • Self test
14548177
1297 }-
1298 lasttp = tp = cp - 1;-
1299-
1300 if (legal_variable_starter (c))
((*__ctype_b_l...int) _ISalpha)Description
TRUEevaluated 7289797 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 35189556 times by 1 test
Evaluated by:
  • Self test
(c == '_')Description
TRUEevaluated 96 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 35189460 times by 1 test
Evaluated by:
  • Self test
96-35189556
1301 {-
1302 /* variable names not preceded with a dollar sign are shell variables. */-
1303 char *savecp;-
1304 EXPR_CONTEXT ec;-
1305 int peektok;-
1306-
1307 while (legal_variable_char (c))
((*__ctype_b_l...int) _ISalnum)Description
TRUEevaluated 39686936 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7292253 times by 1 test
Evaluated by:
  • Self test
c == '_'Description
TRUEevaluated 2360 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7289893 times by 1 test
Evaluated by:
  • Self test
2360-39686936
1308 c = *cp++;
executed 39689296 times by 1 test: c = *cp++;
Executed by:
  • Self test
39689296
1309-
1310 c = *--cp;-
1311-
1312#if defined (ARRAY_VARS)-
1313 if (c == '[')
c == '['Description
TRUEevaluated 10154 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7279739 times by 1 test
Evaluated by:
  • Self test
10154-7279739
1314 {-
1315 e = skipsubscript (cp, 0, 1); /* XXX - arg 3 was 0 */-
1316 if (cp[e] == ']')
cp[e] == ']'Description
TRUEevaluated 10154 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-10154
1317 {-
1318 cp += e + 1;-
1319 c = *cp;-
1320 e = ']';-
1321 }
executed 10154 times by 1 test: end of block
Executed by:
  • Self test
10154
1322 else-
1323 evalerror (bash_badsub_errmsg);
never executed: evalerror (bash_badsub_errmsg);
0
1324 }-
1325#endif /* ARRAY_VARS */-
1326-
1327 *cp = '\0';-
1328 /* XXX - watch out for pointer aliasing issues here */-
1329 if (curlval.tokstr && curlval.tokstr == tokstr)
curlval.tokstrDescription
TRUEevaluated 44688 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7245205 times by 1 test
Evaluated by:
  • Self test
curlval.tokstr == tokstrDescription
TRUEevaluated 44679 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
9-7245205
1330 init_lvalue (&curlval);
executed 44679 times by 1 test: init_lvalue (&curlval);
Executed by:
  • Self test
44679
1331-
1332 FREE (tokstr);
executed 45322 times by 1 test: sh_xfree((tokstr), "expr.c", 1332);
Executed by:
  • Self test
tokstrDescription
TRUEevaluated 45322 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7244571 times by 1 test
Evaluated by:
  • Self test
45322-7244571
1333 tokstr = savestring (tp);-
1334 *cp = c;-
1335-
1336 /* XXX - make peektok part of saved token state? */-
1337 SAVETOK (&ec);-
1338 tokstr = (char *)NULL; /* keep it from being freed */-
1339 tp = savecp = cp;-
1340 noeval = 1;-
1341 curtok = STR;-
1342 readtok ();-
1343 peektok = curtok;-
1344 if (peektok == STR) /* free new tokstr before old one is restored */
peektok == 5Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7289883 times by 1 test
Evaluated by:
  • Self test
9-7289883
1345 FREE (tokstr);
executed 9 times by 1 test: sh_xfree((tokstr), "expr.c", 1345);
Executed by:
  • Self test
executed 9 times by 1 test: end of block
Executed by:
  • Self test
tokstrDescription
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-9
1346 RESTORETOK (&ec);-
1347 cp = savecp;-
1348-
1349 /* The tests for PREINC and PREDEC aren't strictly correct, but they-
1350 preserve old behavior if a construct like --x=9 is given. */-
1351 if (lasttok == PREINC || lasttok == PREDEC || peektok != EQ)
lasttok == 14Description
TRUEevaluated 32 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7289860 times by 1 test
Evaluated by:
  • Self test
lasttok == 15Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7289844 times by 1 test
Evaluated by:
  • Self test
peektok != '='Description
TRUEevaluated 7287236 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2608 times by 1 test
Evaluated by:
  • Self test
16-7289860
1352 {-
1353 lastlval = curlval;-
1354 tokval = expr_streval (tokstr, e, &curlval);-
1355 }
executed 7287274 times by 1 test: end of block
Executed by:
  • Self test
7287274
1356 else-
1357 tokval = 0;
executed 2608 times by 1 test: tokval = 0;
Executed by:
  • Self test
2608
1358-
1359 lasttok = curtok;-
1360 curtok = STR;-
1361 }
executed 7289882 times by 1 test: end of block
Executed by:
  • Self test
7289882
1362 else if (DIGIT(c))
(c) >= '0'Description
TRUEevaluated 14008144 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21181316 times by 1 test
Evaluated by:
  • Self test
(c) <= '9'Description
TRUEevaluated 13898339 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 109805 times by 1 test
Evaluated by:
  • Self test
109805-21181316
1363 {-
1364 while (ISALNUM (c) || c == '#' || c == '@' || c == '_')
((*__ctype_b_l...int) _ISalnum)Description
TRUEevaluated 33140000 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 13898513 times by 1 test
Evaluated by:
  • Self test
c == '#'Description
TRUEevaluated 158 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 13898355 times by 1 test
Evaluated by:
  • Self test
c == '@'Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 13898347 times by 1 test
Evaluated by:
  • Self test
c == '_'Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 13898339 times by 1 test
Evaluated by:
  • Self test
8-33140000
1365 c = *cp++;
executed 33140174 times by 1 test: c = *cp++;
Executed by:
  • Self test
33140174
1366-
1367 c = *--cp;-
1368 *cp = '\0';-
1369-
1370 tokval = strlong (tp);-
1371 *cp = c;-
1372 lasttok = curtok;-
1373 curtok = NUM;-
1374 }
executed 13898307 times by 1 test: end of block
Executed by:
  • Self test
13898307
1375 else-
1376 {-
1377 c1 = *cp++;-
1378 if ((c == EQ) && (c1 == EQ))
(c == '=')Description
TRUEevaluated 7955 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21283166 times by 1 test
Evaluated by:
  • Self test
(c1 == '=')Description
TRUEevaluated 95 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7860 times by 1 test
Evaluated by:
  • Self test
95-21283166
1379 c = EQEQ;
executed 95 times by 1 test: c = 1;
Executed by:
  • Self test
95
1380 else if ((c == NOT) && (c1 == EQ))
(c == '!')Description
TRUEevaluated 41 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21290985 times by 1 test
Evaluated by:
  • Self test
(c1 == '=')Description
TRUEevaluated 26 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 15 times by 1 test
Evaluated by:
  • Self test
15-21290985
1381 c = NEQ;
executed 26 times by 1 test: c = 2;
Executed by:
  • Self test
26
1382 else if ((c == GT) && (c1 == EQ))
(c == '>')Description
TRUEevaluated 11727 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21279273 times by 1 test
Evaluated by:
  • Self test
(c1 == '=')Description
TRUEevaluated 4859 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6868 times by 1 test
Evaluated by:
  • Self test
4859-21279273
1383 c = GEQ;
executed 4859 times by 1 test: c = 4;
Executed by:
  • Self test
4859
1384 else if ((c == LT) && (c1 == EQ))
(c == '<')Description
TRUEevaluated 69555 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21216586 times by 1 test
Evaluated by:
  • Self test
(c1 == '=')Description
TRUEevaluated 19881 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 49674 times by 1 test
Evaluated by:
  • Self test
19881-21216586
1385 c = LEQ;
executed 19881 times by 1 test: c = 3;
Executed by:
  • Self test
19881
1386 else if ((c == LT) && (c1 == LT))
(c == '<')Description
TRUEevaluated 49674 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21216586 times by 1 test
Evaluated by:
  • Self test
(c1 == '<')Description
TRUEevaluated 59 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 49615 times by 1 test
Evaluated by:
  • Self test
59-21216586
1387 {-
1388 if (*cp == '=') /* a <<= b */
*cp == '='Description
TRUEevaluated 48 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 11 times by 1 test
Evaluated by:
  • Self test
11-48
1389 {-
1390 assigntok = LSH;-
1391 c = OP_ASSIGN;-
1392 cp++;-
1393 }
executed 48 times by 1 test: end of block
Executed by:
  • Self test
48
1394 else-
1395 c = LSH;
executed 11 times by 1 test: c = 9;
Executed by:
  • Self test
11
1396 }-
1397 else if ((c == GT) && (c1 == GT))
(c == '>')Description
TRUEevaluated 6868 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21259333 times by 1 test
Evaluated by:
  • Self test
(c1 == '>')Description
TRUEevaluated 48 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6820 times by 1 test
Evaluated by:
  • Self test
48-21259333
1398 {-
1399 if (*cp == '=')
*cp == '='Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 24 times by 1 test
Evaluated by:
  • Self test
24
1400 {-
1401 assigntok = RSH; /* a >>= b */-
1402 c = OP_ASSIGN;-
1403 cp++;-
1404 }
executed 24 times by 1 test: end of block
Executed by:
  • Self test
24
1405 else-
1406 c = RSH;
executed 24 times by 1 test: c = 10;
Executed by:
  • Self test
24
1407 }-
1408 else if ((c == BAND) && (c1 == BAND))
(c == '&')Description
TRUEevaluated 207 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21265946 times by 1 test
Evaluated by:
  • Self test
(c1 == '&')Description
TRUEevaluated 125 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 82 times by 1 test
Evaluated by:
  • Self test
82-21265946
1409 c = LAND;
executed 125 times by 1 test: c = 7;
Executed by:
  • Self test
125
1410 else if ((c == BOR) && (c1 == BOR))
(c == '|')Description
TRUEevaluated 19926 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21246102 times by 1 test
Evaluated by:
  • Self test
(c1 == '|')Description
TRUEevaluated 19837 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 89 times by 1 test
Evaluated by:
  • Self test
89-21246102
1411 c = LOR;
executed 19837 times by 1 test: c = 8;
Executed by:
  • Self test
19837
1412 else if ((c == '*') && (c1 == '*'))
(c == '*')Description
TRUEevaluated 59519 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21186672 times by 1 test
Evaluated by:
  • Self test
(c1 == '*')Description
TRUEevaluated 33 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 59486 times by 1 test
Evaluated by:
  • Self test
33-21186672
1413 c = POWER;
executed 33 times by 1 test: c = 13;
Executed by:
  • Self test
33
1414 else if ((c == '-' || c == '+') && c1 == c && curtok == STR)
c == '-'Description
TRUEevaluated 1354361 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 19891797 times by 1 test
Evaluated by:
  • Self test
c == '+'Description
TRUEevaluated 19586057 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 305740 times by 1 test
Evaluated by:
  • Self test
c1 == cDescription
TRUEevaluated 1420732 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 19519686 times by 1 test
Evaluated by:
  • Self test
curtok == 5Description
TRUEevaluated 1420630 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 102 times by 1 test
Evaluated by:
  • Self test
102-19891797
1415 c = (c == '-') ? POSTDEC : POSTINC;
executed 1420630 times by 1 test: c = (c == '-') ? 17 : 16;
Executed by:
  • Self test
(c == '-')Description
TRUEevaluated 1323966 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 96664 times by 1 test
Evaluated by:
  • Self test
96664-1420630
1416 else if ((c == '-' || c == '+') && c1 == c && curtok == NUM && (lasttok == PREINC || lasttok == PREDEC))
c == '-'Description
TRUEevaluated 30395 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 19795133 times by 1 test
Evaluated by:
  • Self test
c == '+'Description
TRUEevaluated 19489393 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 305740 times by 1 test
Evaluated by:
  • Self test
c1 == cDescription
TRUEevaluated 102 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 19519686 times by 1 test
Evaluated by:
  • Self test
curtok == 6Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 90 times by 1 test
Evaluated by:
  • Self test
lasttok == 14Description
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • Self test
lasttok == 15Description
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • Self test
0-19795133
1417 {-
1418 /* This catches something like --FOO++ */-
1419 if (c == '-')
c == '-'Description
TRUEnever evaluated
FALSEnever evaluated
0
1420 evalerror ("--: assignment requires lvalue");
never executed: evalerror ("--: assignment requires lvalue");
0
1421 else-
1422 evalerror ("++: assignment requires lvalue");
never executed: evalerror ("++: assignment requires lvalue");
0
1423 }-
1424 else if ((c == '-' || c == '+') && c1 == c)
c == '-'Description
TRUEevaluated 30395 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 19795133 times by 1 test
Evaluated by:
  • Self test
c == '+'Description
TRUEevaluated 19489393 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 305740 times by 1 test
Evaluated by:
  • Self test
c1 == cDescription
TRUEevaluated 102 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 19519686 times by 1 test
Evaluated by:
  • Self test
102-19795133
1425 {-
1426 /* Quickly scan forward to see if this is followed by optional-
1427 whitespace and an identifier. */-
1428 xp = cp;-
1429 while (xp && *xp && cr_whitespace (*xp))
xpDescription
TRUEevaluated 128 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
*xpDescription
TRUEevaluated 114 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 14 times by 1 test
Evaluated by:
  • Self test
((*xp) == ' ')Description
TRUEevaluated 26 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 88 times by 1 test
Evaluated by:
  • Self test
((*xp) == '\t')Description
TRUEnever evaluated
FALSEevaluated 88 times by 1 test
Evaluated by:
  • Self test
((*xp) == '\n')Description
TRUEnever evaluated
FALSEevaluated 88 times by 1 test
Evaluated by:
  • Self test
0-128
1430 xp++;
executed 26 times by 1 test: xp++;
Executed by:
  • Self test
26
1431 if (legal_variable_starter ((unsigned char)*xp))
((*__ctype_b_l...int) _ISalpha)Description
TRUEevaluated 48 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 54 times by 1 test
Evaluated by:
  • Self test
((unsigned char)*xp == '_')Description
TRUEnever evaluated
FALSEevaluated 54 times by 1 test
Evaluated by:
  • Self test
0-54
1432 c = (c == '-') ? PREDEC : PREINC;
executed 48 times by 1 test: c = (c == '-') ? 15 : 14;
Executed by:
  • Self test
(c == '-')Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 32 times by 1 test
Evaluated by:
  • Self test
16-48
1433 else-
1434 /* Could force parsing as preinc or predec and throw an error */-
1435#if 0-
1436 {-
1437 /* bash-5.0 */-
1438 /* This catches something like --4++ */-
1439 if (c == '-')-
1440 evalerror ("--: assignment requires lvalue");-
1441 else-
1442 evalerror ("++: assignment requires lvalue");-
1443 }-
1444#else-
1445 cp--; /* not preinc or predec, so unget the character */
executed 54 times by 1 test: cp--;
Executed by:
  • Self test
54
1446#endif-
1447 }-
1448 else if (c1 == EQ && member (c, "*/%+-&^|"))
(c)Description
TRUEevaluated 19517526 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
c1 == '='Description
TRUEevaluated 19517526 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 307900 times by 1 test
Evaluated by:
  • Self test
((c) ? ((char ...id *)0) ) : 0)Description
TRUEevaluated 19517526 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-19517526
1449 {-
1450 assigntok = c; /* a OP= b */-
1451 c = OP_ASSIGN;-
1452 }
executed 19517526 times by 1 test: end of block
Executed by:
  • Self test
19517526
1453 else if (_is_arithop (c) == 0)
_is_arithop (c) == 0Description
TRUEevaluated 48 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 307852 times by 1 test
Evaluated by:
  • Self test
48-307852
1454 {-
1455 cp--;-
1456 /* use curtok, since it hasn't been copied to lasttok yet */-
1457 if (curtok == 0 || _is_arithop (curtok) || _is_multiop (curtok))
curtok == 0Description
TRUEevaluated 31 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 17 times by 1 test
Evaluated by:
  • Self test
_is_arithop (curtok)Description
TRUEnever evaluated
FALSEevaluated 17 times by 1 test
Evaluated by:
  • Self test
_is_multiop (curtok)Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
0-31
1458 evalerror (_("syntax error: operand expected"));
executed 47 times by 1 test: evalerror ( dcgettext (((void *)0), "syntax error: operand expected" , 5) );
Executed by:
  • Self test
47
1459 else-
1460 evalerror (_("syntax error: invalid arithmetic operator"));
executed 1 time by 1 test: evalerror ( dcgettext (((void *)0), "syntax error: invalid arithmetic operator" , 5) );
Executed by:
  • Self test
1
1461 }-
1462 else-
1463 cp--; /* `unget' the character */
executed 307852 times by 1 test: cp--;
Executed by:
  • Self test
307852
1464-
1465 /* Should check here to make sure that the current character is one-
1466 of the recognized operators and flag an error if not. Could create-
1467 a character map the first time through and check it on subsequent-
1468 calls. */-
1469 lasttok = curtok;-
1470 curtok = c;-
1471 }
executed 21291073 times by 1 test: end of block
Executed by:
  • Self test
21291073
1472 tp = cp;-
1473}
executed 42479262 times by 1 test: end of block
Executed by:
  • Self test
42479262
1474-
1475static void-
1476evalerror (msg)-
1477 const char *msg;-
1478{-
1479 char *name, *t;-
1480-
1481 name = this_command_name;-
1482 for (t = expression; t && whitespace (*t); t++)
tDescription
TRUEevaluated 332 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
((*t) == ' ')Description
TRUEevaluated 125 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 207 times by 1 test
Evaluated by:
  • Self test
((*t) == '\t')Description
TRUEnever evaluated
FALSEevaluated 207 times by 1 test
Evaluated by:
  • Self test
0-332
1483 ;
executed 125 times by 1 test: ;
Executed by:
  • Self test
125
1484 internal_error (_("%s%s%s: %s (error token is \"%s\")"),-
1485 name ? name : "", name ? ": " : "",-
1486 t ? t : "", msg, (lasttp && *lasttp) ? lasttp : "");-
1487 sh_longjmp (evalbuf, 1);-
1488}
never executed: end of block
0
1489-
1490/* Convert a string to an intmax_t integer, with an arbitrary base.-
1491 0nnn -> base 8-
1492 0[Xx]nn -> base 16-
1493 Anything else: [base#]number (this is implemented to match ksh93)-
1494-
1495 Base may be >=2 and <=64. If base is <= 36, the numbers are drawn-
1496 from [0-9][a-zA-Z], and lowercase and uppercase letters may be used-
1497 interchangably. If base is > 36 and <= 64, the numbers are drawn-
1498 from [0-9][a-z][A-Z]_@ (a = 10, z = 35, A = 36, Z = 61, @ = 62, _ = 63 ---
1499 you get the picture). */-
1500-
1501static intmax_t-
1502strlong (num)-
1503 char *num;-
1504{-
1505 register char *s;-
1506 register unsigned char c;-
1507 int base, foundbase;-
1508 intmax_t val;-
1509-
1510 s = num;-
1511-
1512 base = 10;-
1513 foundbase = 0;-
1514 if (*s == '0')
*s == '0'Description
TRUEevaluated 35809 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 13862530 times by 1 test
Evaluated by:
  • Self test
35809-13862530
1515 {-
1516 s++;-
1517-
1518 if (*s == '\0')
*s == '\0'Description
TRUEevaluated 34001 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1808 times by 1 test
Evaluated by:
  • Self test
1808-34001
1519 return 0;
executed 34001 times by 1 test: return 0;
Executed by:
  • Self test
34001
1520-
1521 /* Base 16? */-
1522 if (*s == 'x' || *s == 'X')
*s == 'x'Description
TRUEevaluated 1792 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 16 times by 1 test
Evaluated by:
  • Self test
*s == 'X'Description
TRUEnever evaluated
FALSEevaluated 16 times by 1 test
Evaluated by:
  • Self test
0-1792
1523 {-
1524 base = 16;-
1525 s++;-
1526 }
executed 1792 times by 1 test: end of block
Executed by:
  • Self test
1792
1527 else-
1528 base = 8;
executed 16 times by 1 test: base = 8;
Executed by:
  • Self test
16
1529 foundbase++;-
1530 }
executed 1808 times by 1 test: end of block
Executed by:
  • Self test
1808
1531-
1532 val = 0;-
1533 for (c = *s++; c; c = *s++)
cDescription
TRUEevaluated 33102525 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 13864306 times by 1 test
Evaluated by:
  • Self test
13864306-33102525
1534 {-
1535 if (c == '#')
c == '#'Description
TRUEevaluated 158 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 33102367 times by 1 test
Evaluated by:
  • Self test
158-33102367
1536 {-
1537 if (foundbase)
foundbaseDescription
TRUEevaluated 16 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 142 times by 1 test
Evaluated by:
  • Self test
16-142
1538 evalerror (_("invalid number"));
executed 16 times by 1 test: evalerror ( dcgettext (((void *)0), "invalid number" , 5) );
Executed by:
  • Self test
16
1539-
1540 /* Illegal base specifications raise an evaluation error. */-
1541 if (val < 2 || val > 64)
val < 2Description
TRUEnever evaluated
FALSEevaluated 142 times by 1 test
Evaluated by:
  • Self test
val > 64Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 134 times by 1 test
Evaluated by:
  • Self test
0-142
1542 evalerror (_("invalid arithmetic base"));
executed 8 times by 1 test: evalerror ( dcgettext (((void *)0), "invalid arithmetic base" , 5) );
Executed by:
  • Self test
8
1543-
1544 base = val;-
1545 val = 0;-
1546 foundbase++;-
1547 }
executed 134 times by 1 test: end of block
Executed by:
  • Self test
134
1548 else if (ISALNUM(c) || (c == '_') || (c == '@'))
((*__ctype_b_l...int) _ISalnum)Description
TRUEevaluated 33102351 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 16 times by 1 test
Evaluated by:
  • Self test
(c == '_')Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
(c == '@')Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-33102351
1549 {-
1550 if (DIGIT(c))
(c) >= '0'Description
TRUEevaluated 33102367 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(c) <= '9'Description
TRUEevaluated 33100977 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1390 times by 1 test
Evaluated by:
  • Self test
0-33102367
1551 c = TODIGIT(c);
executed 33100977 times by 1 test: c = ((c) - '0');
Executed by:
  • Self test
33100977
1552 else if (c >= 'a' && c <= 'z')
c >= 'a'Description
TRUEevaluated 1127 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 263 times by 1 test
Evaluated by:
  • Self test
c <= 'z'Description
TRUEevaluated 1127 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1127
1553 c -= 'a' - 10;
executed 1127 times by 1 test: c -= 'a' - 10;
Executed by:
  • Self test
1127
1554 else if (c >= 'A' && c <= 'Z')
c >= 'A'Description
TRUEevaluated 255 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
c <= 'Z'Description
TRUEevaluated 247 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
8-255
1555 c -= 'A' - ((base <= 36) ? 10 : 36);
executed 247 times by 1 test: c -= 'A' - ((base <= 36) ? 10 : 36);
Executed by:
  • Self test
(base <= 36)Description
TRUEevaluated 231 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 16 times by 1 test
Evaluated by:
  • Self test
16-247
1556 else if (c == '@')
c == '@'Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
8
1557 c = 62;
executed 8 times by 1 test: c = 62;
Executed by:
  • Self test
8
1558 else if (c == '_')
c == '_'Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-8
1559 c = 63;
executed 8 times by 1 test: c = 63;
Executed by:
  • Self test
8
1560-
1561 if (c >= base)
c >= baseDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 33102359 times by 1 test
Evaluated by:
  • Self test
8-33102359
1562 evalerror (_("value too great for base"));
executed 8 times by 1 test: evalerror ( dcgettext (((void *)0), "value too great for base" , 5) );
Executed by:
  • Self test
8
1563-
1564 val = (val * base) + c;-
1565 }
executed 33102359 times by 1 test: end of block
Executed by:
  • Self test
33102359
1566 else-
1567 break;
never executed: break;
0
1568 }-
1569-
1570 return (val);
executed 13864306 times by 1 test: return (val);
Executed by:
  • Self test
13864306
1571}-
1572-
1573#if defined (EXPR_TEST)-
1574void *-
1575xmalloc (n)-
1576 int n;-
1577{-
1578 return (malloc (n));-
1579}-
1580-
1581void *-
1582xrealloc (s, n)-
1583 char *s;-
1584 int n;-
1585{-
1586 return (realloc (s, n));-
1587}-
1588-
1589SHELL_VAR *find_variable () { return 0;}-
1590SHELL_VAR *bind_variable () { return 0; }-
1591-
1592char *get_string_value () { return 0; }-
1593-
1594procenv_t top_level;-
1595-
1596main (argc, argv)-
1597 int argc;-
1598 char **argv;-
1599{-
1600 register int i;-
1601 intmax_t v;-
1602 int expok;-
1603-
1604 if (setjmp (top_level))-
1605 exit (0);-
1606-
1607 for (i = 1; i < argc; i++)-
1608 {-
1609 v = evalexp (argv[i], 0, &expok);-
1610 if (expok == 0)-
1611 fprintf (stderr, _("%s: expression error\n"), argv[i]);-
1612 else-
1613 printf ("'%s' -> %ld\n", argv[i], v);-
1614 }-
1615 exit (0);-
1616}-
1617-
1618int-
1619builtin_error (format, arg1, arg2, arg3, arg4, arg5)-
1620 char *format;-
1621{-
1622 fprintf (stderr, "expr: ");-
1623 fprintf (stderr, format, arg1, arg2, arg3, arg4, arg5);-
1624 fprintf (stderr, "\n");-
1625 return 0;-
1626}-
1627-
1628char *-
1629itos (n)-
1630 intmax_t n;-
1631{-
1632 return ("42");-
1633}-
1634-
1635#endif /* EXPR_TEST */-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2