OpenCoverage

expr.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/src/expr.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* expr -- evaluate expressions.-
2 Copyright (C) 1986-2018 Free Software Foundation, Inc.-
3-
4 This program is free software: you can redistribute it and/or modify-
5 it under the terms of the GNU General Public License as published by-
6 the Free Software Foundation, either version 3 of the License, or-
7 (at your option) any later version.-
8-
9 This program is distributed in the hope that it will be useful,-
10 but WITHOUT ANY WARRANTY; without even the implied warranty of-
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
12 GNU General Public License for more details.-
13-
14 You should have received a copy of the GNU General Public License-
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */-
16-
17/* Author: Mike Parker.-
18 Modified for arbitrary-precision calculation by James Youngman.-
19-
20 This program evaluates expressions. Each token (operator, operand,-
21 parenthesis) of the expression must be a separate argument. The-
22 parser used is a reasonably general one, though any incarnation of-
23 it is language-specific. It is especially nice for expressions.-
24-
25 No parse tree is needed; a new node is evaluated immediately.-
26 One function can handle multiple operators all of equal precedence,-
27 provided they all associate ((x op x) op x).-
28-
29 Define EVAL_TRACE to print an evaluation trace. */-
30-
31#include <config.h>-
32#include <stdio.h>-
33#include <sys/types.h>-
34#include "system.h"-
35-
36#include <regex.h>-
37#include "die.h"-
38#include "error.h"-
39#include "long-options.h"-
40#include "mbuiter.h"-
41#include "strnumcmp.h"-
42#include "xstrtol.h"-
43-
44/* Various parts of this code assume size_t fits into unsigned long-
45 int, the widest unsigned type that GMP supports. */-
46verify (SIZE_MAX <= ULONG_MAX);-
47-
48#ifndef HAVE_GMP-
49# define HAVE_GMP 0-
50#endif-
51-
52#if HAVE_GMP-
53# include <gmp.h>-
54#else-
55static void integer_overflow (char) ATTRIBUTE_NORETURN;-
56/* Approximate gmp.h well enough for expr.c's purposes. */-
57typedef intmax_t mpz_t[1];-
58static
executed 4993 times by 1 test: end of block
Executed by:
  • expr
void mpz_clear (mpz_t z) { (void) z; }
executed 4993 times by 1 test: end of block
Executed by:
  • expr
4993
59static
executed 830 times by 1 test: end of block
Executed by:
  • expr
void mpz_init_set_ui (mpz_t z, unsigned long int i) { z[0] = i; }
executed 830 times by 1 test: end of block
Executed by:
  • expr
830
60static int-
61mpz_init_set_str (mpz_t z, char *s, int base)-
62{-
63 return xstrtoimax (s, NULL, base, z, NULL) == LONGINT_OK ? 0 : -1;
executed 8375 times by 1 test: return xstrtoimax (s, ((void *)0) , base, z, ((void *)0) ) == LONGINT_OK ? 0 : -1;
Executed by:
  • expr
8375
64}-
65static void-
66mpz_add (mpz_t r, mpz_t a0, mpz_t b0)-
67{-
68 intmax_t a = a0[0];-
69 intmax_t b = b0[0];-
70 intmax_t val = a + b;-
71 if ((val < a) != (b < 0))
(val < a) != (b < 0)Description
TRUEnever evaluated
FALSEevaluated 2851 times by 1 test
Evaluated by:
  • expr
0-2851
72 integer_overflow ('+');
never executed: integer_overflow ('+');
0
73 r[0] = val;-
74}
executed 2851 times by 1 test: end of block
Executed by:
  • expr
2851
75static void-
76mpz_sub (mpz_t r, mpz_t a0, mpz_t b0)-
77{-
78 intmax_t a = a0[0];-
79 intmax_t b = b0[0];-
80 intmax_t val = a - b;-
81 if ((a < val) != (b < 0))
(a < val) != (b < 0)Description
TRUEnever evaluated
FALSEevaluated 11 times by 1 test
Evaluated by:
  • expr
0-11
82 integer_overflow ('-');
never executed: integer_overflow ('-');
0
83 r[0] = val;-
84}
executed 11 times by 1 test: end of block
Executed by:
  • expr
11
85static void-
86mpz_mul (mpz_t r, mpz_t a0, mpz_t b0)-
87{-
88 intmax_t a = a0[0];-
89 intmax_t b = b0[0];-
90 intmax_t val = a * b;-
91 if (! (a == 0 || b == 0
a == 0Description
TRUEnever evaluated
FALSEevaluated 512 times by 1 test
Evaluated by:
  • expr
b == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • expr
FALSEevaluated 511 times by 1 test
Evaluated by:
  • expr
0-512
92 || ((val < 0) == ((a < 0) ^ (b < 0)) && val / a == b)))
(val < 0) == (... 0) ^ (b < 0))Description
TRUEevaluated 511 times by 1 test
Evaluated by:
  • expr
FALSEnever evaluated
val / a == bDescription
TRUEevaluated 511 times by 1 test
Evaluated by:
  • expr
FALSEnever evaluated
0-511
93 integer_overflow ('*');
never executed: integer_overflow ('*');
0
94 r[0] = val;-
95}
executed 512 times by 1 test: end of block
Executed by:
  • expr
512
96static void-
97mpz_tdiv_q (mpz_t r, mpz_t a0, mpz_t b0)-
98{-
99 intmax_t a = a0[0];-
100 intmax_t b = b0[0];-
101-
102 /* Some x86-style hosts raise an exception for INT_MIN / -1. */-
103 if (a < - INTMAX_MAX && b == -1)
a < - (9223372036854775807L)Description
TRUEnever evaluated
FALSEevaluated 815 times by 1 test
Evaluated by:
  • expr
b == -1Description
TRUEnever evaluated
FALSEnever evaluated
0-815
104 integer_overflow ('/');
never executed: integer_overflow ('/');
0
105 r[0] = a / b;-
106}
executed 815 times by 1 test: end of block
Executed by:
  • expr
815
107static void-
108mpz_tdiv_r (mpz_t r, mpz_t a0, mpz_t b0)-
109{-
110 intmax_t a = a0[0];-
111 intmax_t b = b0[0];-
112-
113 /* Some x86-style hosts raise an exception for INT_MIN % -1. */-
114 r[0] = a < - INTMAX_MAX && b == -1 ? 0 : a % b;
a < - (9223372036854775807L)Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • expr
b == -1Description
TRUEnever evaluated
FALSEnever evaluated
0-8
115}
executed 8 times by 1 test: end of block
Executed by:
  • expr
8
116static char *-
117mpz_get_str (char const *str, int base, mpz_t z)-
118{-
119 (void) str; (void) base;-
120 char buf[INT_BUFSIZE_BOUND (intmax_t)];-
121 return xstrdup (imaxtostr (z[0], buf));
executed 796 times by 1 test: return xstrdup (imaxtostr (z[0], buf));
Executed by:
  • expr
796
122}-
123static int-
124mpz_sgn (mpz_t z)-
125{-
126 return z[0] < 0 ? -1 : 0 < z[0];
executed 5033 times by 1 test: return z[0] < 0 ? -1 : 0 < z[0];
Executed by:
  • expr
5033
127}-
128static int-
129mpz_fits_ulong_p (mpz_t z)-
130{-
131 return 0 <= z[0] && z[0] <= ULONG_MAX;
never executed: return 0 <= z[0] && z[0] <= (0x7fffffffffffffffL * 2UL + 1UL) ;
0
132}-
133static unsigned long int-
134mpz_get_ui (mpz_t z)-
135{-
136 return z[0];
never executed: return z[0];
0
137}-
138static int-
139mpz_out_str (FILE *stream, int base, mpz_t z)-
140{-
141 (void) base;-
142 char buf[INT_BUFSIZE_BOUND (intmax_t)];-
143 return fputs (imaxtostr (z[0], buf), stream) != EOF;
executed 4210 times by 1 test: return fputs_unlocked (imaxtostr (z[0], buf),stream) != (-1) ;
Executed by:
  • expr
4210
144}-
145#endif-
146-
147/* The official name of this program (e.g., no 'g' prefix). */-
148#define PROGRAM_NAME "expr"-
149-
150#define AUTHORS \-
151 proper_name ("Mike Parker"), \-
152 proper_name ("James Youngman"), \-
153 proper_name ("Paul Eggert")-
154-
155/* Exit statuses. */-
156enum-
157 {-
158 /* Invalid expression: e.g., its form does not conform to the-
159 grammar for expressions. Our grammar is an extension of the-
160 POSIX grammar. */-
161 EXPR_INVALID = 2,-
162-
163 /* An internal error occurred, e.g., arithmetic overflow, storage-
164 exhaustion. */-
165 EXPR_FAILURE-
166 };-
167-
168/* The kinds of value we can have. */-
169enum valtype-
170{-
171 integer,-
172 string-
173};-
174typedef enum valtype TYPE;-
175-
176/* A value is.... */-
177struct valinfo-
178{-
179 TYPE type; /* Which kind. */-
180 union-
181 { /* The value itself. */-
182 mpz_t i;-
183 char *s;-
184 } u;-
185};-
186typedef struct valinfo VALUE;-
187-
188/* The arguments given to the program, minus the program name. */-
189static char **args;-
190-
191static VALUE *eval (bool);-
192static bool nomoreargs (void);-
193static bool null (VALUE *v);-
194static void printv (VALUE *v);-
195-
196-
197/*-
198 Find the first occurrence in the character string STRING of any character-
199 in the character string ACCEPT.-
200-
201 Copied from gnulib's mbscspn, with two differences:-
202 1. Returns 1-based position of first found character, or zero if not found.-
203 2. Returned value is the logical character index, NOT byte offset.-
204-
205 Examples:-
206 mbs_logical_cspn ('hello','a') => 0-
207 mbs_logical_cspn ('hello','h') => 1-
208 mbs_logical_cspn ('hello','oe') => 1-
209 mbs_logical_cspn ('hello','lo') => 3-
210-
211 In UTF-8 \xCE\xB1 is a single character (greek alpha):-
212 mbs_logical_cspn ('\xCE\xB1bc','\xCE\xB1') => 1-
213 mbs_logical_cspn ('\xCE\xB1bc','c') => 3 */-
214static size_t-
215mbs_logical_cspn (const char *s, const char *accept)-
216{-
217 size_t idx = 0;-
218-
219 if (accept[0] == '\0')
accept[0] == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
0
220 return 0;
never executed: return 0;
0
221-
222 /* General case. */-
223 if (MB_CUR_MAX > 1)
(__ctype_get_m...ur_max ()) > 1Description
TRUEnever evaluated
FALSEnever evaluated
0
224 {-
225 mbui_iterator_t iter;-
226-
227 for (mbui_init (iter, s); mbui_avail (iter); mbui_advance (iter))
((iter).cur).wc_validDescription
TRUEnever evaluated
FALSEnever evaluated
((iter).cur).wc == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
228 {-
229 ++idx;-
230 if (mb_len (mbui_cur (iter)) == 1)
(((iter).cur).bytes) == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
231 {-
232 if (mbschr (accept, *mbui_cur_ptr (iter)))
mbschr (accept...iter).cur.ptr)Description
TRUEnever evaluated
FALSEnever evaluated
0
233 return idx;
never executed: return idx;
0
234 }
never executed: end of block
0
235 else-
236 {-
237 mbui_iterator_t aiter;-
238-
239 for (mbui_init (aiter, accept);-
240 mbui_avail (aiter);
((aiter).cur).wc_validDescription
TRUEnever evaluated
FALSEnever evaluated
((aiter).cur).wc == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
241 mbui_advance (aiter))-
242 if (mb_equal (mbui_cur (aiter), mbui_cur (iter)))
(((aiter).cur)...).bytes) == 0)Description
TRUEnever evaluated
FALSEnever evaluated
((aiter).cur).wc_validDescription
TRUEnever evaluated
FALSEnever evaluated
((iter).cur).wc_validDescription
TRUEnever evaluated
FALSEnever evaluated
((aiter).cur)....er).cur).bytesDescription
TRUEnever evaluated
FALSEnever evaluated
memcmp (((aite...r).bytes) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
243 return idx;
never executed: return idx;
0
244 }
never executed: end of block
0
245 }-
246-
247 /* not found */-
248 return 0;
never executed: return 0;
0
249 }-
250 else-
251 {-
252 /* single-byte locale,-
253 convert returned byte offset to 1-based index or zero if not found. */-
254 size_t i = strcspn (s, accept);-
255 return (s[i] ? i + 1 : 0);
never executed: return (s[i] ? i + 1 : 0);
0
256 }-
257}-
258-
259/* Extract the substring of S, from logical character-
260 position POS and LEN characters.-
261 first character position is 1.-
262 POS and LEN refer to logical characters, not octets.-
263-
264 Upon exit, sets v->s to the new string.-
265 The new string might be empty if POS/LEN are invalid. */-
266static char *-
267mbs_logical_substr (const char *s, size_t pos, size_t len)-
268{-
269 char *v, *vlim;-
270-
271 size_t blen = strlen (s); /* byte length */-
272 size_t llen = (MB_CUR_MAX > 1) ? mbslen (s) : blen; /* logical length */
( (__ctype_get...r_max ()) > 1)Description
TRUEnever evaluated
FALSEnever evaluated
0
273-
274 if (llen < pos || pos == 0 || len == 0 || len == SIZE_MAX)
llen < posDescription
TRUEnever evaluated
FALSEnever evaluated
pos == 0Description
TRUEnever evaluated
FALSEnever evaluated
len == 0Description
TRUEnever evaluated
FALSEnever evaluated
len == (184467...73709551615UL)Description
TRUEnever evaluated
FALSEnever evaluated
0
275 return xstrdup ("");
never executed: return xstrdup ("");
0
276-
277 /* characters to copy */-
278 size_t vlen = MIN (len, llen - pos + 1);
(( len )<( llen - pos + 1 ))Description
TRUEnever evaluated
FALSEnever evaluated
0
279-
280 if (MB_CUR_MAX == 1)
(__ctype_get_m...r_max ()) == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
281 {-
282 /* Single-byte case */-
283 v = xmalloc (vlen + 1);-
284 vlim = mempcpy (v, s + pos - 1, vlen);-
285 }
never executed: end of block
0
286 else-
287 {-
288 /* Multibyte case */-
289-
290 /* FIXME: this is wasteful. Some memory can be saved by counting-
291 how many bytes the matching characters occupy. */-
292 vlim = v = xmalloc (blen + 1);-
293-
294 mbui_iterator_t iter;-
295 size_t idx=1;-
296 for (mbui_init (iter, s);-
297 mbui_avail (iter) && vlen > 0;
((iter).cur).wc_validDescription
TRUEnever evaluated
FALSEnever evaluated
((iter).cur).wc == 0Description
TRUEnever evaluated
FALSEnever evaluated
vlen > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
298 mbui_advance (iter), ++idx)-
299 {-
300 /* Skip until we reach the starting position */-
301 if (idx < pos)
idx < posDescription
TRUEnever evaluated
FALSEnever evaluated
0
302 continue;
never executed: continue;
0
303-
304 /* Copy one character */-
305 --vlen;-
306 vlim = mempcpy (vlim, mbui_cur_ptr (iter), mb_len (mbui_cur (iter)));-
307 }
never executed: end of block
0
308 }
never executed: end of block
0
309 *vlim = '\0';-
310 return v;
never executed: return v;
0
311}-
312-
313/* Return the number of logical characteres (possibly multibyte)-
314 that are in string S in the first OFS octets.-
315-
316 Example in UTF-8:-
317 "\xE2\x9D\xA7" is "U+2767 ROTATED FLORAL HEART BULLET".-
318 In the string below, there are only two characters-
319 up to the first 4 bytes (The U+2767 which occupies 3 bytes and 'x'):-
320 mbs_count_to_offset ("\xE2\x9D\xA7xyz", 4) => 2 */-
321static size_t-
322mbs_offset_to_chars (const char *s, size_t ofs)-
323{-
324 mbui_iterator_t iter;-
325 size_t c = 0;-
326 for (mbui_init (iter, s); mbui_avail (iter); mbui_advance (iter))
((iter).cur).wc_validDescription
TRUEnever evaluated
FALSEnever evaluated
((iter).cur).wc == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
327 {-
328 ptrdiff_t d = mbui_cur_ptr (iter) - s;-
329 if (d >= ofs)
d >= ofsDescription
TRUEnever evaluated
FALSEnever evaluated
0
330 break;
never executed: break;
0
331 ++c;-
332 }
never executed: end of block
0
333 return c;
never executed: return c;
0
334}-
335-
336-
337-
338void-
339usage (int status)-
340{-
341 if (status != EXIT_SUCCESS)
status != 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • expr
FALSEevaluated 2 times by 1 test
Evaluated by:
  • expr
1-2
342 emit_try_help ();
executed 1 time by 1 test: end of block
Executed by:
  • expr
1
343 else-
344 {-
345 printf (_("\-
346Usage: %s EXPRESSION\n\-
347 or: %s OPTION\n\-
348"),-
349 program_name, program_name);-
350 putchar ('\n');-
351 fputs (HELP_OPTION_DESCRIPTION, stdout);-
352 fputs (VERSION_OPTION_DESCRIPTION, stdout);-
353 fputs (_("\-
354\n\-
355Print the value of EXPRESSION to standard output. A blank line below\n\-
356separates increasing precedence groups. EXPRESSION may be:\n\-
357\n\-
358 ARG1 | ARG2 ARG1 if it is neither null nor 0, otherwise ARG2\n\-
359\n\-
360 ARG1 & ARG2 ARG1 if neither argument is null or 0, otherwise 0\n\-
361"), stdout);-
362 fputs (_("\-
363\n\-
364 ARG1 < ARG2 ARG1 is less than ARG2\n\-
365 ARG1 <= ARG2 ARG1 is less than or equal to ARG2\n\-
366 ARG1 = ARG2 ARG1 is equal to ARG2\n\-
367 ARG1 != ARG2 ARG1 is unequal to ARG2\n\-
368 ARG1 >= ARG2 ARG1 is greater than or equal to ARG2\n\-
369 ARG1 > ARG2 ARG1 is greater than ARG2\n\-
370"), stdout);-
371 fputs (_("\-
372\n\-
373 ARG1 + ARG2 arithmetic sum of ARG1 and ARG2\n\-
374 ARG1 - ARG2 arithmetic difference of ARG1 and ARG2\n\-
375"), stdout);-
376 /* Tell xgettext that the "% A" below is not a printf-style-
377 format string: xgettext:no-c-format */-
378 fputs (_("\-
379\n\-
380 ARG1 * ARG2 arithmetic product of ARG1 and ARG2\n\-
381 ARG1 / ARG2 arithmetic quotient of ARG1 divided by ARG2\n\-
382 ARG1 % ARG2 arithmetic remainder of ARG1 divided by ARG2\n\-
383"), stdout);-
384 fputs (_("\-
385\n\-
386 STRING : REGEXP anchored pattern match of REGEXP in STRING\n\-
387\n\-
388 match STRING REGEXP same as STRING : REGEXP\n\-
389 substr STRING POS LENGTH substring of STRING, POS counted from 1\n\-
390 index STRING CHARS index in STRING where any CHARS is found, or 0\n\-
391 length STRING length of STRING\n\-
392"), stdout);-
393 fputs (_("\-
394 + TOKEN interpret TOKEN as a string, even if it is a\n\-
395 keyword like 'match' or an operator like '/'\n\-
396\n\-
397 ( EXPRESSION ) value of EXPRESSION\n\-
398"), stdout);-
399 fputs (_("\-
400\n\-
401Beware that many operators need to be escaped or quoted for shells.\n\-
402Comparisons are arithmetic if both ARGs are numbers, else lexicographical.\n\-
403Pattern matches return the string matched between \\( and \\) or null; if\n\-
404\\( and \\) are not used, they return the number of characters matched or 0.\n\-
405"), stdout);-
406 fputs (_("\-
407\n\-
408Exit status is 0 if EXPRESSION is neither null nor 0, 1 if EXPRESSION is null\n\-
409or 0, 2 if EXPRESSION is syntactically invalid, and 3 if an error occurred.\n\-
410"), stdout);-
411 emit_ancillary_info (PROGRAM_NAME);-
412 }
executed 2 times by 1 test: end of block
Executed by:
  • expr
2
413 exit (status);
executed 3 times by 1 test: exit (status);
Executed by:
  • expr
3
414}-
415-
416-
417#if ! HAVE_GMP-
418/* Report an integer overflow for operation OP and exit. */-
419static void-
420integer_overflow (char op)-
421{-
422 die (EXPR_FAILURE, ERANGE, "%c", op);-
423}
never executed: end of block
0
424#endif-
425-
426int-
427main (int argc, char **argv)-
428{-
429 VALUE *v;-
430-
431 initialize_main (&argc, &argv);-
432 set_program_name (argv[0]);-
433 setlocale (LC_ALL, "");-
434 bindtextdomain (PACKAGE, LOCALEDIR);-
435 textdomain (PACKAGE);-
436-
437 initialize_exit_failure (EXPR_FAILURE);-
438 atexit (close_stdout);-
439-
440 parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, VERSION,-
441 usage, AUTHORS, (char const *) NULL);-
442-
443 /* The above handles --help and --version.-
444 Since there is no other invocation of getopt, handle '--' here. */-
445 unsigned int u_argc = argc;-
446 if (1 < u_argc && STREQ (argv[1], "--"))
never executed: __result = (((const unsigned char *) (const char *) ( argv[1] ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "--" ))[3] - __s2[3]);
executed 5 times by 1 test: end of block
Executed by:
  • expr
executed 10 times by 1 test: end of block
Executed by:
  • expr
1 < u_argcDescription
TRUEevaluated 4852 times by 1 test
Evaluated by:
  • expr
FALSEevaluated 1 time by 1 test
Evaluated by:
  • expr
( __extension_...)))); }) == 0)Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • expr
FALSEevaluated 4847 times by 1 test
Evaluated by:
  • expr
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEevaluated 4852 times by 1 test
Evaluated by:
  • expr
FALSEnever evaluated
__result == 0Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • expr
FALSEevaluated 4842 times by 1 test
Evaluated by:
  • expr
__s2_len > 1Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • expr
FALSEnever evaluated
__result == 0Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • expr
FALSEevaluated 5 times by 1 test
Evaluated by:
  • expr
__s2_len > 2Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • expr
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-4852
447 {-
448 --u_argc;-
449 ++argv;-
450 }
executed 5 times by 1 test: end of block
Executed by:
  • expr
5
451-
452 if (u_argc <= 1)
u_argc <= 1Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • expr
FALSEevaluated 4852 times by 1 test
Evaluated by:
  • expr
1-4852
453 {-
454 error (0, 0, _("missing operand"));-
455 usage (EXPR_INVALID);-
456 }
never executed: end of block
0
457-
458 args = argv + 1;-
459-
460 v = eval (true);-
461 if (!nomoreargs ())
!nomoreargs ()Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • expr
FALSEevaluated 4832 times by 1 test
Evaluated by:
  • expr
2-4832
462 die (EXPR_INVALID, 0, _("syntax error: unexpected argument %s"),
executed 2 times by 1 test: ((!!sizeof (struct { _Static_assert (EXPR_INVALID, "verify_expr (" "EXPR_INVALID" ", " "(error (EXPR_INVALID, 0, dcgettext (((void *)0), \"syntax error: unexpected argument %s\", 5), quotearg_n_style (0, locale_quoting_style, *args)), assume (false))" ")"...rgs)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error (EXPR_INVALID, 0, dcgettext (((void *)0), "syntax error: unexpected argument %s" , 5) , quotearg_n_style (0, locale_quoting_style, *args)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • expr
2
463 quotearg_n_style (0, locale_quoting_style, *args));
executed 2 times by 1 test: ((!!sizeof (struct { _Static_assert (EXPR_INVALID, "verify_expr (" "EXPR_INVALID" ", " "(error (EXPR_INVALID, 0, dcgettext (((void *)0), \"syntax error: unexpected argument %s\", 5), quotearg_n_style (0, locale_quoting_style, *args)), assume (false))" ")"...rgs)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error (EXPR_INVALID, 0, dcgettext (((void *)0), "syntax error: unexpected argument %s" , 5) , quotearg_n_style (0, locale_quoting_style, *args)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • expr
2
464-
465 printv (v);-
466-
467 return null (v);
executed 4832 times by 1 test: return null (v);
Executed by:
  • expr
4832
468}-
469-
470/* Return a VALUE for I. */-
471-
472static VALUE *-
473int_value (unsigned long int i)-
474{-
475 VALUE *v = xmalloc (sizeof *v);-
476 v->type = integer;-
477 mpz_init_set_ui (v->u.i, i);-
478 return v;
executed 830 times by 1 test: return v;
Executed by:
  • expr
830
479}-
480-
481/* Return a VALUE for S. */-
482-
483static VALUE *-
484str_value (char const *s)-
485{-
486 VALUE *v = xmalloc (sizeof *v);-
487 v->type = string;-
488 v->u.s = xstrdup (s);-
489 return v;
executed 11138 times by 1 test: return v;
Executed by:
  • expr
11138
490}-
491-
492/* Free VALUE V, including structure components. */-
493-
494static void-
495freev (VALUE *v)-
496{-
497 if (v->type == string)
v->type == stringDescription
TRUEevaluated 2907 times by 1 test
Evaluated by:
  • expr
FALSEevaluated 4197 times by 1 test
Evaluated by:
  • expr
2907-4197
498 free (v->u.s);
executed 2907 times by 1 test: free (v->u.s);
Executed by:
  • expr
2907
499 else-
500 mpz_clear (v->u.i);
executed 4197 times by 1 test: mpz_clear (v->u.i);
Executed by:
  • expr
4197
501 free (v);-
502}
executed 7104 times by 1 test: end of block
Executed by:
  • expr
7104
503-
504/* Print VALUE V. */-
505-
506static void-
507printv (VALUE *v)-
508{-
509 switch (v->type)-
510 {-
511 case integer:
executed 4210 times by 1 test: case integer:
Executed by:
  • expr
4210
512 mpz_out_str (stdout, 10, v->u.i);-
513 putchar ('\n');-
514 break;
executed 4210 times by 1 test: break;
Executed by:
  • expr
4210
515 case string:
executed 622 times by 1 test: case string:
Executed by:
  • expr
622
516 puts (v->u.s);-
517 break;
executed 622 times by 1 test: break;
Executed by:
  • expr
622
518 default:
never executed: default:
0
519 abort ();
never executed: abort ();
0
520 }-
521}-
522-
523/* Return true if V is a null-string or zero-number. */-
524-
525static bool _GL_ATTRIBUTE_PURE-
526null (VALUE *v)-
527{-
528 switch (v->type)-
529 {-
530 case integer:
executed 4210 times by 1 test: case integer:
Executed by:
  • expr
4210
531 return mpz_sgn (v->u.i) == 0;
executed 4210 times by 1 test: return mpz_sgn (v->u.i) == 0;
Executed by:
  • expr
4210
532 case string:
executed 629 times by 1 test: case string:
Executed by:
  • expr
629
533 {-
534 char const *cp = v->u.s;-
535 if (*cp == '\0')
*cp == '\0'Description
TRUEevaluated 25 times by 1 test
Evaluated by:
  • expr
FALSEevaluated 604 times by 1 test
Evaluated by:
  • expr
25-604
536 return true;
executed 25 times by 1 test: return 1 ;
Executed by:
  • expr
25
537-
538 cp += (*cp == '-');-
539-
540 do-
541 {-
542 if (*cp != '0')
*cp != '0'Description
TRUEevaluated 600 times by 1 test
Evaluated by:
  • expr
FALSEevaluated 5 times by 1 test
Evaluated by:
  • expr
5-600
543 return false;
executed 600 times by 1 test: return 0 ;
Executed by:
  • expr
600
544 }
executed 5 times by 1 test: end of block
Executed by:
  • expr
5
545 while (*++cp);
*++cpDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • expr
FALSEevaluated 4 times by 1 test
Evaluated by:
  • expr
1-4
546-
547 return true;
executed 4 times by 1 test: return 1 ;
Executed by:
  • expr
4
548 }-
549 default:
never executed: default:
0
550 abort ();
never executed: abort ();
0
551 }-
552}-
553-
554/* Return true if CP takes the form of an integer. */-
555-
556static bool _GL_ATTRIBUTE_PURE-
557looks_like_integer (char const *cp)-
558{-
559 cp += (*cp == '-');-
560-
561 do-
562 if (! ISDIGIT (*cp))
! ((unsigned i...p) - '0' <= 9)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • expr
FALSEevaluated 24174 times by 1 test
Evaluated by:
  • expr
2-24174
563 return false;
executed 2 times by 1 test: return 0 ;
Executed by:
  • expr
2
564 while (*++cp);
*++cpDescription
TRUEevaluated 14204 times by 1 test
Evaluated by:
  • expr
FALSEevaluated 9970 times by 1 test
Evaluated by:
  • expr
9970-14204
565-
566 return true;
executed 9970 times by 1 test: return 1 ;
Executed by:
  • expr
9970
567}-
568-
569/* Coerce V to a string value (can't fail). */-
570-
571static void-
572tostring (VALUE *v)-
573{-
574 switch (v->type)-
575 {-
576 case integer:
executed 796 times by 1 test: case integer:
Executed by:
  • expr
796
577 {-
578 char *s = mpz_get_str (NULL, 10, v->u.i);-
579 mpz_clear (v->u.i);-
580 v->u.s = s;-
581 v->type = string;-
582 }-
583 break;
executed 796 times by 1 test: break;
Executed by:
  • expr
796
584 case string:
executed 2126 times by 1 test: case string:
Executed by:
  • expr
2126
585 break;
executed 2126 times by 1 test: break;
Executed by:
  • expr
2126
586 default:
never executed: default:
0
587 abort ();
never executed: abort ();
0
588 }-
589}-
590-
591/* Coerce V to an integer value. Return true on success, false on failure. */-
592-
593static bool-
594toarith (VALUE *v)-
595{-
596 switch (v->type)-
597 {-
598 case integer:
executed 21 times by 1 test: case integer:
Executed by:
  • expr
21
599 return true;
executed 21 times by 1 test: return 1 ;
Executed by:
  • expr
21
600 case string:
executed 8376 times by 1 test: case string:
Executed by:
  • expr
8376
601 {-
602 char *s = v->u.s;-
603-
604 if (! looks_like_integer (s))
! looks_like_integer (s)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • expr
FALSEevaluated 8375 times by 1 test
Evaluated by:
  • expr
1-8375
605 return false;
executed 1 time by 1 test: return 0 ;
Executed by:
  • expr
1
606 if (mpz_init_set_str (v->u.i, s, 10) != 0 && !HAVE_GMP)
mpz_init_set_s...i, s, 10) != 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • expr
FALSEevaluated 8374 times by 1 test
Evaluated by:
  • expr
1-8374
607 die (EXPR_FAILURE, ERANGE, "%s", (s));
executed 1 time by 1 test: ((!!sizeof (struct { _Static_assert (EXPR_FAILURE, "verify_expr (" "EXPR_FAILURE" ", " "(error (EXPR_FAILURE, 34, \"%s\", (s)), assume (false))" ")"); int _gl_dummy; })) ? ((error (EXPR_FAILURE, 34 , "%s", (s)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error (EXPR_FAILURE, 34 , "%s", (s)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
Executed by:
  • expr
1
608 free (s);-
609 v->type = integer;-
610 return true;
executed 8374 times by 1 test: return 1 ;
Executed by:
  • expr
8374
611 }-
612 default:
never executed: default:
0
613 abort ();
never executed: abort ();
0
614 }-
615}-
616-
617/* Extract a size_t value from an integer value I.-
618 If the value is negative, return SIZE_MAX.-
619 If the value is too large, return SIZE_MAX - 1. */-
620static size_t-
621getsize (mpz_t i)-
622{-
623 if (mpz_sgn (i) < 0)
mpz_sgn (i) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
624 return SIZE_MAX;
never executed: return (18446744073709551615UL) ;
0
625 if (mpz_fits_ulong_p (i))
mpz_fits_ulong_p (i)Description
TRUEnever evaluated
FALSEnever evaluated
0
626 {-
627 unsigned long int ul = mpz_get_ui (i);-
628 if (ul < SIZE_MAX)
ul < (18446744073709551615UL)Description
TRUEnever evaluated
FALSEnever evaluated
0
629 return ul;
never executed: return ul;
0
630 }
never executed: end of block
0
631 return SIZE_MAX - 1;
never executed: return (18446744073709551615UL) - 1;
0
632}-
633-
634/* Return true and advance if the next token matches STR exactly.-
635 STR must not be NULL. */-
636-
637static bool-
638nextarg (char const *str)-
639{-
640 if (*args == NULL)
*args == ((void *)0)Description
TRUEevaluated 72514 times by 1 test
Evaluated by:
  • expr
FALSEevaluated 97983 times by 1 test
Evaluated by:
  • expr
72514-97983
641 return false;
executed 72514 times by 1 test: return 0 ;
Executed by:
  • expr
72514
642 else-
643 {-
644 bool r = STREQ (*args, str);
never executed: __result = (((const unsigned char *) (const char *) ( *args ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( str ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
645 args += r;-
646 return r;
executed 97983 times by 1 test: return r;
Executed by:
  • expr
97983
647 }-
648}-
649-
650/* Return true if there no more tokens. */-
651-
652static bool-
653nomoreargs (void)-
654{-
655 return *args == 0;
executed 15373 times by 1 test: return *args == 0;
Executed by:
  • expr
15373
656}-
657-
658/* Report missing operand.-
659 There is an implicit assumption that there was a previous argument,-
660 and (args-1) is valid. */-
661static void-
662require_more_args (void)-
663{-
664 if (nomoreargs ())
nomoreargs ()Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • expr
FALSEevaluated 10526 times by 1 test
Evaluated by:
  • expr
3-10526
665 die (EXPR_INVALID, 0, _("syntax error: missing argument after %s"),
executed 3 times by 1 test: ((!!sizeof (struct { _Static_assert (EXPR_INVALID, "verify_expr (" "EXPR_INVALID" ", " "(error (EXPR_INVALID, 0, dcgettext (((void *)0), \"syntax error: missing argument after %s\", 5), quotearg_n_style (0, locale_quoting_style, *(args-1))), assume (false...(( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error (EXPR_INVALID, 0, dcgettext (((void *)0), "syntax error: missing argument after %s" , 5) , quotearg_n_style (0, locale_quoting_style, *(args-1))), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • expr
3
666 quotearg_n_style (0, locale_quoting_style, *(args-1)));
executed 3 times by 1 test: ((!!sizeof (struct { _Static_assert (EXPR_INVALID, "verify_expr (" "EXPR_INVALID" ", " "(error (EXPR_INVALID, 0, dcgettext (((void *)0), \"syntax error: missing argument after %s\", 5), quotearg_n_style (0, locale_quoting_style, *(args-1))), assume (false...(( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error (EXPR_INVALID, 0, dcgettext (((void *)0), "syntax error: missing argument after %s" , 5) , quotearg_n_style (0, locale_quoting_style, *(args-1))), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • expr
3
667}
executed 10526 times by 1 test: end of block
Executed by:
  • expr
10526
668-
669-
670#ifdef EVAL_TRACE-
671/* Print evaluation trace and args remaining. */-
672-
673static void-
674trace (fxn)-
675 char *fxn;-
676{-
677 char **a;-
678-
679 printf ("%s:", fxn);-
680 for (a = args; *a; a++)-
681 printf (" %s", *a);-
682 putchar ('\n');-
683}-
684#endif-
685-
686/* Do the : operator.-
687 SV is the VALUE for the lhs (the string),-
688 PV is the VALUE for the rhs (the pattern). */-
689-
690static VALUE *-
691docolon (VALUE *sv, VALUE *pv)-
692{-
693 VALUE *v IF_LINT ( = NULL);-
694 const char *errmsg;-
695 struct re_pattern_buffer re_buffer;-
696 char fastmap[UCHAR_MAX + 1];-
697 struct re_registers re_regs;-
698 regoff_t matchlen;-
699-
700 tostring (sv);-
701 tostring (pv);-
702-
703 re_regs.num_regs = 0;-
704 re_regs.start = NULL;-
705 re_regs.end = NULL;-
706-
707 re_buffer.buffer = NULL;-
708 re_buffer.allocated = 0;-
709 re_buffer.fastmap = fastmap;-
710 re_buffer.translate = NULL;-
711 re_syntax_options =-
712 RE_SYNTAX_POSIX_BASIC & ~RE_CONTEXT_INVALID_DUP & ~RE_NO_EMPTY_RANGES;-
713 errmsg = re_compile_pattern (pv->u.s, strlen (pv->u.s), &re_buffer);-
714 if (errmsg)
errmsgDescription
TRUEevaluated 11 times by 1 test
Evaluated by:
  • expr
FALSEevaluated 652 times by 1 test
Evaluated by:
  • expr
11-652
715 die (EXPR_INVALID, 0, "%s", (errmsg));
executed 11 times by 1 test: ((!!sizeof (struct { _Static_assert (EXPR_INVALID, "verify_expr (" "EXPR_INVALID" ", " "(error (EXPR_INVALID, 0, \"%s\", (errmsg)), assume (false))" ")"); int _gl_dummy; })) ? ((error (EXPR_INVALID, 0, "%s", (errmsg)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error (EXPR_INVALID, 0, "%s", (errmsg)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
Executed by:
  • expr
11
716 re_buffer.newline_anchor = 0;-
717-
718 matchlen = re_match (&re_buffer, sv->u.s, strlen (sv->u.s), 0, &re_regs);-
719 if (0 <= matchlen)
0 <= matchlenDescription
TRUEevaluated 646 times by 1 test
Evaluated by:
  • expr
FALSEevaluated 6 times by 1 test
Evaluated by:
  • expr
6-646
720 {-
721 /* Were \(...\) used? */-
722 if (re_buffer.re_nsub > 0)
re_buffer.re_nsub > 0Description
TRUEevaluated 617 times by 1 test
Evaluated by:
  • expr
FALSEevaluated 29 times by 1 test
Evaluated by:
  • expr
29-617
723 {-
724 sv->u.s[re_regs.end[1]] = '\0';-
725 v = str_value (sv->u.s + re_regs.start[1]);-
726 }
executed 617 times by 1 test: end of block
Executed by:
  • expr
617
727 else-
728 {-
729 /* In multibyte locales, convert the matched offset (=number of bytes)-
730 to the number of matched characters. */-
731 size_t i = (MB_CUR_MAX == 1
(__ctype_get_m...r_max ()) == 1Description
TRUEevaluated 29 times by 1 test
Evaluated by:
  • expr
FALSEnever evaluated
0-29
732 ? matchlen-
733 : mbs_offset_to_chars (sv->u.s, matchlen));-
734 v = int_value (i);-
735 }
executed 29 times by 1 test: end of block
Executed by:
  • expr
29
736 }-
737 else if (matchlen == -1)
matchlen == -1Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • expr
FALSEnever evaluated
0-6
738 {-
739 /* Match failed -- return the right kind of null. */-
740 if (re_buffer.re_nsub > 0)
re_buffer.re_nsub > 0Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • expr
FALSEevaluated 1 time by 1 test
Evaluated by:
  • expr
1-5
741 v = str_value ("");
executed 5 times by 1 test: v = str_value ("");
Executed by:
  • expr
5
742 else-
743 v = int_value (0);
executed 1 time by 1 test: v = int_value (0);
Executed by:
  • expr
1
744 }-
745 else-
746 die (EXPR_FAILURE,
never executed: ((!!sizeof (struct { _Static_assert (EXPR_FAILURE, "verify_expr (" "EXPR_FAILURE" ", " "(error (EXPR_FAILURE, (matchlen == -2 ? (*__errno_location ()) : 75), dcgettext (((void *)0), \"error in regular expression matcher\", 5)), assume (false))" ")"); int ...her" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error (EXPR_FAILURE, (matchlen == -2 ? (*__errno_location ()) : 75 ), dcgettext (((void *)0), "error in regular expression matcher" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
747 (matchlen == -2 ? errno : EOVERFLOW),
never executed: ((!!sizeof (struct { _Static_assert (EXPR_FAILURE, "verify_expr (" "EXPR_FAILURE" ", " "(error (EXPR_FAILURE, (matchlen == -2 ? (*__errno_location ()) : 75), dcgettext (((void *)0), \"error in regular expression matcher\", 5)), assume (false))" ")"); int ...her" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error (EXPR_FAILURE, (matchlen == -2 ? (*__errno_location ()) : 75 ), dcgettext (((void *)0), "error in regular expression matcher" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
748 _("error in regular expression matcher"));
never executed: ((!!sizeof (struct { _Static_assert (EXPR_FAILURE, "verify_expr (" "EXPR_FAILURE" ", " "(error (EXPR_FAILURE, (matchlen == -2 ? (*__errno_location ()) : 75), dcgettext (((void *)0), \"error in regular expression matcher\", 5)), assume (false))" ")"); int ...her" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error (EXPR_FAILURE, (matchlen == -2 ? (*__errno_location ()) : 75 ), dcgettext (((void *)0), "error in regular expression matcher" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
749-
750 if (0 < re_regs.num_regs)
0 < re_regs.num_regsDescription
TRUEevaluated 646 times by 1 test
Evaluated by:
  • expr
FALSEevaluated 6 times by 1 test
Evaluated by:
  • expr
6-646
751 {-
752 free (re_regs.start);-
753 free (re_regs.end);-
754 }
executed 646 times by 1 test: end of block
Executed by:
  • expr
646
755 re_buffer.fastmap = NULL;-
756 regfree (&re_buffer);-
757 return v;
executed 652 times by 1 test: return v;
Executed by:
  • expr
652
758}-
759-
760/* Handle bare operands and ( expr ) syntax. */-
761-
762static VALUE *-
763eval7 (bool evaluate)-
764{-
765 VALUE *v;-
766-
767#ifdef EVAL_TRACE-
768 trace ("eval7");-
769#endif-
770 require_more_args ();-
771-
772 if (nextarg ("("))
nextarg ("(")Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • expr
FALSEevaluated 10516 times by 1 test
Evaluated by:
  • expr
10-10516
773 {-
774 v = eval (evaluate);-
775 if (nomoreargs ())
nomoreargs ()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • expr
FALSEevaluated 9 times by 1 test
Evaluated by:
  • expr
1-9
776 die (EXPR_INVALID, 0, _("syntax error: expecting ')' after %s"),
executed 1 time by 1 test: ((!!sizeof (struct { _Static_assert (EXPR_INVALID, "verify_expr (" "EXPR_INVALID" ", " "(error (EXPR_INVALID, 0, dcgettext (((void *)0), \"syntax error: expecting ')' after %s\", 5), quotearg_n_style (0, locale_quoting_style, *(args-1))), assume (false))"...), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error (EXPR_INVALID, 0, dcgettext (((void *)0), "syntax error: expecting ')' after %s" , 5) , quotearg_n_style (0, locale_quoting_style, *(args-1))), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • expr
1
777 quotearg_n_style (0, locale_quoting_style, *(args-1)));
executed 1 time by 1 test: ((!!sizeof (struct { _Static_assert (EXPR_INVALID, "verify_expr (" "EXPR_INVALID" ", " "(error (EXPR_INVALID, 0, dcgettext (((void *)0), \"syntax error: expecting ')' after %s\", 5), quotearg_n_style (0, locale_quoting_style, *(args-1))), assume (false))"...), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error (EXPR_INVALID, 0, dcgettext (((void *)0), "syntax error: expecting ')' after %s" , 5) , quotearg_n_style (0, locale_quoting_style, *(args-1))), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • expr
1
778 if (!nextarg (")"))
!nextarg (")")Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • expr
FALSEevaluated 8 times by 1 test
Evaluated by:
  • expr
1-8
779 die (EXPR_INVALID, 0, _("syntax error: expecting ')' instead of %s"),
executed 1 time by 1 test: ((!!sizeof (struct { _Static_assert (EXPR_INVALID, "verify_expr (" "EXPR_INVALID" ", " "(error (EXPR_INVALID, 0, dcgettext (((void *)0), \"syntax error: expecting ')' instead of %s\", 5), quotearg_n_style (0, locale_quoting_style, *args)), assume (false))..., (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error (EXPR_INVALID, 0, dcgettext (((void *)0), "syntax error: expecting ')' instead of %s" , 5) , quotearg_n_style (0, locale_quoting_style, *args)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • expr
1
780 quotearg_n_style (0, locale_quoting_style, *args));
executed 1 time by 1 test: ((!!sizeof (struct { _Static_assert (EXPR_INVALID, "verify_expr (" "EXPR_INVALID" ", " "(error (EXPR_INVALID, 0, dcgettext (((void *)0), \"syntax error: expecting ')' instead of %s\", 5), quotearg_n_style (0, locale_quoting_style, *args)), assume (false))..., (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error (EXPR_INVALID, 0, dcgettext (((void *)0), "syntax error: expecting ')' instead of %s" , 5) , quotearg_n_style (0, locale_quoting_style, *args)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • expr
1
781 return v;
executed 8 times by 1 test: return v;
Executed by:
  • expr
8
782 }-
783-
784 if (nextarg (")"))
nextarg (")")Description
TRUEnever evaluated
FALSEevaluated 10516 times by 1 test
Evaluated by:
  • expr
0-10516
785 die (EXPR_INVALID, 0, _("syntax error: unexpected ')'"));
never executed: ((!!sizeof (struct { _Static_assert (EXPR_INVALID, "verify_expr (" "EXPR_INVALID" ", " "(error (EXPR_INVALID, 0, dcgettext (((void *)0), \"syntax error: unexpected ')'\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error (EXPR_INVALID, 0, dcgettext (((void *)0), "syntax error: unexpected ')'" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error (EXPR_INVALID, 0, dcgettext (((void *)0), "syntax error: unexpected ')'" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
786-
787 return str_value (*args++);
executed 10516 times by 1 test: return str_value (*args++);
Executed by:
  • expr
10516
788}-
789-
790/* Handle match, substr, index, and length keywords, and quoting "+". */-
791-
792static VALUE *-
793eval6 (bool evaluate)-
794{-
795 VALUE *l;-
796 VALUE *r;-
797 VALUE *v;-
798 VALUE *i1;-
799 VALUE *i2;-
800-
801#ifdef EVAL_TRACE-
802 trace ("eval6");-
803#endif-
804 if (nextarg ("+"))
nextarg ("+")Description
TRUEnever evaluated
FALSEevaluated 10530 times by 1 test
Evaluated by:
  • expr
0-10530
805 {-
806 require_more_args ();-
807 return str_value (*args++);
never executed: return str_value (*args++);
0
808 }-
809 else if (nextarg ("length"))
nextarg ("length")Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • expr
FALSEevaluated 10529 times by 1 test
Evaluated by:
  • expr
1-10529
810 {-
811 r = eval6 (evaluate);-
812 tostring (r);-
813 v = int_value (mbslen (r->u.s));-
814 freev (r);-
815 return v;
never executed: return v;
0
816 }-
817 else if (nextarg ("match"))
nextarg ("match")Description
TRUEnever evaluated
FALSEevaluated 10529 times by 1 test
Evaluated by:
  • expr
0-10529
818 {-
819 l = eval6 (evaluate);-
820 r = eval6 (evaluate);-
821 if (evaluate)
evaluateDescription
TRUEnever evaluated
FALSEnever evaluated
0
822 {-
823 v = docolon (l, r);-
824 freev (l);-
825 }
never executed: end of block
0
826 else-
827 v = l;
never executed: v = l;
0
828 freev (r);-
829 return v;
never executed: return v;
0
830 }-
831 else if (nextarg ("index"))
nextarg ("index")Description
TRUEnever evaluated
FALSEevaluated 10529 times by 1 test
Evaluated by:
  • expr
0-10529
832 {-
833 size_t pos;-
834-
835 l = eval6 (evaluate);-
836 r = eval6 (evaluate);-
837 tostring (l);-
838 tostring (r);-
839 pos = mbs_logical_cspn (l->u.s, r->u.s);-
840 v = int_value (pos);-
841 freev (l);-
842 freev (r);-
843 return v;
never executed: return v;
0
844 }-
845 else if (nextarg ("substr"))
nextarg ("substr")Description
TRUEnever evaluated
FALSEevaluated 10529 times by 1 test
Evaluated by:
  • expr
0-10529
846 {-
847 l = eval6 (evaluate);-
848 i1 = eval6 (evaluate);-
849 i2 = eval6 (evaluate);-
850 tostring (l);-
851-
852 if (!toarith (i1) || !toarith (i2))
!toarith (i1)Description
TRUEnever evaluated
FALSEnever evaluated
!toarith (i2)Description
TRUEnever evaluated
FALSEnever evaluated
0
853 v = str_value ("");
never executed: v = str_value ("");
0
854 else-
855 {-
856 size_t pos = getsize (i1->u.i);-
857 size_t len = getsize (i2->u.i);-
858-
859 char *s = mbs_logical_substr (l->u.s, pos, len);-
860 v = str_value (s);-
861 free (s);-
862 }
never executed: end of block
0
863 freev (l);-
864 freev (i1);-
865 freev (i2);-
866 return v;
never executed: return v;
0
867 }-
868 else-
869 return eval7 (evaluate);
executed 10529 times by 1 test: return eval7 (evaluate);
Executed by:
  • expr
10529
870}-
871-
872/* Handle : operator (pattern matching).-
873 Calls docolon to do the real work. */-
874-
875static VALUE *-
876eval5 (bool evaluate)-
877{-
878 VALUE *l;-
879 VALUE *r;-
880 VALUE *v;-
881-
882#ifdef EVAL_TRACE-
883 trace ("eval5");-
884#endif-
885 l = eval6 (evaluate);-
886 while (1)-
887 {-
888 if (nextarg (":"))
nextarg (":")Description
TRUEevaluated 664 times by 1 test
Evaluated by:
  • expr
FALSEevaluated 9849 times by 1 test
Evaluated by:
  • expr
664-9849
889 {-
890 r = eval6 (evaluate);-
891 if (evaluate)
evaluateDescription
TRUEevaluated 663 times by 1 test
Evaluated by:
  • expr
FALSEnever evaluated
0-663
892 {-
893 v = docolon (l, r);-
894 freev (l);-
895 l = v;-
896 }
executed 652 times by 1 test: end of block
Executed by:
  • expr
652
897 freev (r);-
898 }
executed 652 times by 1 test: end of block
Executed by:
  • expr
652
899 else-
900 return l;
executed 9849 times by 1 test: return l;
Executed by:
  • expr
9849
901 }-
902}
never executed: end of block
0
903-
904/* Handle *, /, % operators. */-
905-
906static VALUE *-
907eval4 (bool evaluate)-
908{-
909 VALUE *l;-
910 VALUE *r;-
911 enum { multiply, divide, mod } fxn;-
912-
913#ifdef EVAL_TRACE-
914 trace ("eval4");-
915#endif-
916 l = eval5 (evaluate);-
917 while (1)-
918 {-
919 if (nextarg ("*"))
nextarg ("*")Description
TRUEevaluated 513 times by 1 test
Evaluated by:
  • expr
FALSEevaluated 9335 times by 1 test
Evaluated by:
  • expr
513-9335
920 fxn = multiply;
executed 513 times by 1 test: fxn = multiply;
Executed by:
  • expr
513
921 else if (nextarg ("/"))
nextarg ("/")Description
TRUEevaluated 817 times by 1 test
Evaluated by:
  • expr
FALSEevaluated 8518 times by 1 test
Evaluated by:
  • expr
817-8518
922 fxn = divide;
executed 817 times by 1 test: fxn = divide;
Executed by:
  • expr
817
923 else if (nextarg ("%"))
nextarg ("%")Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • expr
FALSEevaluated 8510 times by 1 test
Evaluated by:
  • expr
8-8510
924 fxn = mod;
executed 8 times by 1 test: fxn = mod;
Executed by:
  • expr
8
925 else-
926 return l;
executed 8510 times by 1 test: return l;
Executed by:
  • expr
8510
927 r = eval5 (evaluate);-
928 if (evaluate)
evaluateDescription
TRUEevaluated 1336 times by 1 test
Evaluated by:
  • expr
FALSEevaluated 2 times by 1 test
Evaluated by:
  • expr
2-1336
929 {-
930 if (!toarith (l) || !toarith (r))
!toarith (l)Description
TRUEnever evaluated
FALSEevaluated 1335 times by 1 test
Evaluated by:
  • expr
!toarith (r)Description
TRUEnever evaluated
FALSEevaluated 1335 times by 1 test
Evaluated by:
  • expr
0-1335
931 die (EXPR_INVALID, 0, _("non-integer argument"));
never executed: ((!!sizeof (struct { _Static_assert (EXPR_INVALID, "verify_expr (" "EXPR_INVALID" ", " "(error (EXPR_INVALID, 0, dcgettext (((void *)0), \"non-integer argument\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error (EXPR_INVALID, 0, dcgettext (((void *)0), "non-integer argument" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error (EXPR_INVALID, 0, dcgettext (((void *)0), "non-integer argument" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
932 if (fxn != multiply && mpz_sgn (r->u.i) == 0)
fxn != multiplyDescription
TRUEevaluated 823 times by 1 test
Evaluated by:
  • expr
FALSEevaluated 512 times by 1 test
Evaluated by:
  • expr
mpz_sgn (r->u.i) == 0Description
TRUEnever evaluated
FALSEevaluated 823 times by 1 test
Evaluated by:
  • expr
0-823
933 die (EXPR_INVALID, 0, _("division by zero"));
never executed: ((!!sizeof (struct { _Static_assert (EXPR_INVALID, "verify_expr (" "EXPR_INVALID" ", " "(error (EXPR_INVALID, 0, dcgettext (((void *)0), \"division by zero\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error (EXPR_INVALID, 0, dcgettext (((void *)0), "division by zero" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error (EXPR_INVALID, 0, dcgettext (((void *)0), "division by zero" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
934 ((fxn == multiply ? mpz_mul-
935 : fxn == divide ? mpz_tdiv_q-
936 : mpz_tdiv_r)-
937 (l->u.i, l->u.i, r->u.i));-
938 }
executed 1335 times by 1 test: end of block
Executed by:
  • expr
1335
939 freev (r);-
940 }
executed 1337 times by 1 test: end of block
Executed by:
  • expr
1337
941}
never executed: end of block
0
942-
943/* Handle +, - operators. */-
944-
945static VALUE *-
946eval3 (bool evaluate)-
947{-
948 VALUE *l;-
949 VALUE *r;-
950 enum { plus, minus } fxn;-
951-
952#ifdef EVAL_TRACE-
953 trace ("eval3");-
954#endif-
955 l = eval4 (evaluate);-
956 while (1)-
957 {-
958 if (nextarg ("+"))
nextarg ("+")Description
TRUEevaluated 2853 times by 1 test
Evaluated by:
  • expr
FALSEevaluated 5656 times by 1 test
Evaluated by:
  • expr
2853-5656
959 fxn = plus;
executed 2853 times by 1 test: fxn = plus;
Executed by:
  • expr
2853
960 else if (nextarg ("-"))
nextarg ("-")Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • expr
FALSEevaluated 5645 times by 1 test
Evaluated by:
  • expr
11-5645
961 fxn = minus;
executed 11 times by 1 test: fxn = minus;
Executed by:
  • expr
11
962 else-
963 return l;
executed 5645 times by 1 test: return l;
Executed by:
  • expr
5645
964 r = eval4 (evaluate);-
965 if (evaluate)
evaluateDescription
TRUEevaluated 2863 times by 1 test
Evaluated by:
  • expr
FALSEnever evaluated
0-2863
966 {-
967 if (!toarith (l) || !toarith (r))
!toarith (l)Description
TRUEnever evaluated
FALSEevaluated 2863 times by 1 test
Evaluated by:
  • expr
!toarith (r)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • expr
FALSEevaluated 2862 times by 1 test
Evaluated by:
  • expr
0-2863
968 die (EXPR_INVALID, 0, _("non-integer argument"));
executed 1 time by 1 test: ((!!sizeof (struct { _Static_assert (EXPR_INVALID, "verify_expr (" "EXPR_INVALID" ", " "(error (EXPR_INVALID, 0, dcgettext (((void *)0), \"non-integer argument\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error (EXPR_INVALID, 0, dcgettext (((void *)0), "non-integer argument" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error (EXPR_INVALID, 0, dcgettext (((void *)0), "non-integer argument" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
Executed by:
  • expr
1
969 (fxn == plus ? mpz_add : mpz_sub) (l->u.i, l->u.i, r->u.i);-
970 }
executed 2862 times by 1 test: end of block
Executed by:
  • expr
2862
971 freev (r);-
972 }
executed 2862 times by 1 test: end of block
Executed by:
  • expr
2862
973}
never executed: end of block
0
974-
975/* Handle comparisons. */-
976-
977static VALUE *-
978eval2 (bool evaluate)-
979{-
980 VALUE *l;-
981-
982#ifdef EVAL_TRACE-
983 trace ("eval2");-
984#endif-
985 l = eval3 (evaluate);-
986 while (1)-
987 {-
988 VALUE *r;-
989 enum-
990 {-
991 less_than, less_equal, equal, not_equal, greater_equal, greater_than-
992 } fxn;-
993 bool val = false;-
994-
995 if (nextarg ("<"))
nextarg ("<")Description
TRUEevaluated 798 times by 1 test
Evaluated by:
  • expr
FALSEevaluated 4847 times by 1 test
Evaluated by:
  • expr
798-4847
996 fxn = less_than;
executed 798 times by 1 test: fxn = less_than;
Executed by:
  • expr
798
997 else if (nextarg ("<="))
nextarg ("<=")Description
TRUEnever evaluated
FALSEevaluated 4847 times by 1 test
Evaluated by:
  • expr
0-4847
998 fxn = less_equal;
never executed: fxn = less_equal;
0
999 else if (nextarg ("=") || nextarg ("=="))
nextarg ("=")Description
TRUEnever evaluated
FALSEevaluated 4847 times by 1 test
Evaluated by:
  • expr
nextarg ("==")Description
TRUEnever evaluated
FALSEevaluated 4847 times by 1 test
Evaluated by:
  • expr
0-4847
1000 fxn = equal;
never executed: fxn = equal;
0
1001 else if (nextarg ("!="))
nextarg ("!=")Description
TRUEnever evaluated
FALSEevaluated 4847 times by 1 test
Evaluated by:
  • expr
0-4847
1002 fxn = not_equal;
never executed: fxn = not_equal;
0
1003 else if (nextarg (">="))
nextarg (">=")Description
TRUEnever evaluated
FALSEevaluated 4847 times by 1 test
Evaluated by:
  • expr
0-4847
1004 fxn = greater_equal;
never executed: fxn = greater_equal;
0
1005 else if (nextarg (">"))
nextarg (">")Description
TRUEnever evaluated
FALSEevaluated 4847 times by 1 test
Evaluated by:
  • expr
0-4847
1006 fxn = greater_than;
never executed: fxn = greater_than;
0
1007 else-
1008 return l;
executed 4847 times by 1 test: return l;
Executed by:
  • expr
4847
1009 r = eval3 (evaluate);-
1010-
1011 if (evaluate)
evaluateDescription
TRUEevaluated 798 times by 1 test
Evaluated by:
  • expr
FALSEnever evaluated
0-798
1012 {-
1013 int cmp;-
1014 tostring (l);-
1015 tostring (r);-
1016-
1017 if (looks_like_integer (l->u.s) && looks_like_integer (r->u.s))
looks_like_integer (l->u.s)Description
TRUEevaluated 798 times by 1 test
Evaluated by:
  • expr
FALSEnever evaluated
looks_like_integer (r->u.s)Description
TRUEevaluated 797 times by 1 test
Evaluated by:
  • expr
FALSEevaluated 1 time by 1 test
Evaluated by:
  • expr
0-798
1018 cmp = strintcmp (l->u.s, r->u.s);
executed 797 times by 1 test: cmp = strintcmp (l->u.s, r->u.s);
Executed by:
  • expr
797
1019 else-
1020 {-
1021 errno = 0;-
1022 cmp = strcoll (l->u.s, r->u.s);-
1023-
1024 if (errno)
(*__errno_location ())Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • expr
0-1
1025 {-
1026 error (0, errno, _("string comparison failed"));-
1027 error (0, 0, _("set LC_ALL='C' to work around the problem"));-
1028 die (EXPR_INVALID, 0,-
1029 _("the strings compared were %s and %s"),-
1030 quotearg_n_style (0, locale_quoting_style, l->u.s),-
1031 quotearg_n_style (1, locale_quoting_style, r->u.s));-
1032 }
never executed: end of block
0
1033 }
executed 1 time by 1 test: end of block
Executed by:
  • expr
1
1034-
1035 switch (fxn)-
1036 {-
1037 case less_than: val = (cmp < 0); break;
executed 798 times by 1 test: break;
Executed by:
  • expr
executed 798 times by 1 test: case less_than:
Executed by:
  • expr
798
1038 case less_equal: val = (cmp <= 0); break;
never executed: break;
never executed: case less_equal:
0
1039 case equal: val = (cmp == 0); break;
never executed: break;
never executed: case equal:
0
1040 case not_equal: val = (cmp != 0); break;
never executed: break;
never executed: case not_equal:
0
1041 case greater_equal: val = (cmp >= 0); break;
never executed: break;
never executed: case greater_equal:
0
1042 case greater_than: val = (cmp > 0); break;
never executed: break;
never executed: case greater_than:
0
1043 default: abort ();
never executed: abort ();
never executed: default:
0
1044 }-
1045 }-
1046-
1047 freev (l);-
1048 freev (r);-
1049 l = int_value (val);-
1050 }
executed 798 times by 1 test: end of block
Executed by:
  • expr
798
1051}
never executed: end of block
0
1052-
1053/* Handle &. */-
1054-
1055static VALUE *-
1056eval1 (bool evaluate)-
1057{-
1058 VALUE *l;-
1059 VALUE *r;-
1060-
1061#ifdef EVAL_TRACE-
1062 trace ("eval1");-
1063#endif-
1064 l = eval2 (evaluate);-
1065 while (1)-
1066 {-
1067 if (nextarg ("&"))
nextarg ("&")Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • expr
FALSEevaluated 4846 times by 1 test
Evaluated by:
  • expr
1-4846
1068 {-
1069 r = eval2 (evaluate && !null (l));-
1070 if (null (l) || null (r))
null (l)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • expr
FALSEnever evaluated
null (r)Description
TRUEnever evaluated
FALSEnever evaluated
0-1
1071 {-
1072 freev (l);-
1073 freev (r);-
1074 l = int_value (0);-
1075 }
executed 1 time by 1 test: end of block
Executed by:
  • expr
1
1076 else-
1077 freev (r);
never executed: freev (r);
0
1078 }-
1079 else-
1080 return l;
executed 4846 times by 1 test: return l;
Executed by:
  • expr
4846
1081 }-
1082}
never executed: end of block
0
1083-
1084/* Handle |. */-
1085-
1086static VALUE *-
1087eval (bool evaluate)-
1088{-
1089 VALUE *l;-
1090 VALUE *r;-
1091-
1092#ifdef EVAL_TRACE-
1093 trace ("eval");-
1094#endif-
1095 l = eval1 (evaluate);-
1096 while (1)-
1097 {-
1098 if (nextarg ("|"))
nextarg ("|")Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • expr
FALSEevaluated 4844 times by 1 test
Evaluated by:
  • expr
2-4844
1099 {-
1100 r = eval1 (evaluate && null (l));-
1101 if (null (l))
null (l)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • expr
FALSEevaluated 1 time by 1 test
Evaluated by:
  • expr
1
1102 {-
1103 freev (l);-
1104 l = r;-
1105 if (null (l))
null (l)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • expr
FALSEnever evaluated
0-1
1106 {-
1107 freev (l);-
1108 l = int_value (0);-
1109 }
executed 1 time by 1 test: end of block
Executed by:
  • expr
1
1110 }
executed 1 time by 1 test: end of block
Executed by:
  • expr
1
1111 else-
1112 freev (r);
executed 1 time by 1 test: freev (r);
Executed by:
  • expr
1
1113 }-
1114 else-
1115 return l;
executed 4844 times by 1 test: return l;
Executed by:
  • expr
4844
1116 }-
1117}
never executed: end of block
0
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2