aboutsummaryrefslogtreecommitdiffstats
path: root/src/expr.c
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2016-10-15 23:10:35 +0100
committerPádraig Brady <P@draigBrady.com>2016-10-16 12:23:55 +0100
commit492dcb2eb191b844a2fd5e51db3eed85289bea1f (patch)
tree910f93d88891b573520ebd5c812d61ddc7fbeed8 /src/expr.c
parentbuild: also distribute new file, src/die.h (diff)
downloadcoreutils-492dcb2eb191b844a2fd5e51db3eed85289bea1f.tar.gz
coreutils-492dcb2eb191b844a2fd5e51db3eed85289bea1f.zip
all: use die() rather than error(EXIT_FAILURE)
die() has the advantage of being apparent to the compiler that it doesn't return, which will avoid warnings in some cases, and possibly generate better code. * cfg.mk (sc_die_EXIT_FAILURE): A new syntax check rule to catch any new uses of error (CONSTANT, ...);
Diffstat (limited to 'src/expr.c')
-rw-r--r--src/expr.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/expr.c b/src/expr.c
index 86eb1361f..d7106ecdd 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -34,6 +34,7 @@
#include "system.h"
#include <regex.h>
+#include "die.h"
#include "error.h"
#include "long-options.h"
#include "strnumcmp.h"
@@ -273,7 +274,7 @@ or 0, 2 if EXPRESSION is syntactically invalid, and 3 if an error occurred.\n\
static void
syntax_error (void)
{
- error (EXPR_INVALID, 0, _("syntax error"));
+ die (EXPR_INVALID, 0, _("syntax error"));
}
#if ! HAVE_GMP
@@ -281,7 +282,7 @@ syntax_error (void)
static void
integer_overflow (char op)
{
- error (EXPR_FAILURE, ERANGE, "%c", op);
+ die (EXPR_FAILURE, ERANGE, "%c", op);
abort (); /* notreached */
}
#endif
@@ -465,7 +466,7 @@ toarith (VALUE *v)
if (! looks_like_integer (s))
return false;
if (mpz_init_set_str (v->u.i, s, 10) != 0 && !HAVE_GMP)
- error (EXPR_FAILURE, ERANGE, "%s", (s));
+ die (EXPR_FAILURE, ERANGE, "%s", (s));
free (s);
v->type = integer;
return true;
@@ -561,7 +562,7 @@ docolon (VALUE *sv, VALUE *pv)
RE_SYNTAX_POSIX_BASIC & ~RE_CONTEXT_INVALID_DUP & ~RE_NO_EMPTY_RANGES;
errmsg = re_compile_pattern (pv->u.s, strlen (pv->u.s), &re_buffer);
if (errmsg)
- error (EXPR_INVALID, 0, "%s", (errmsg));
+ die (EXPR_INVALID, 0, "%s", (errmsg));
re_buffer.newline_anchor = 0;
matchlen = re_match (&re_buffer, sv->u.s, strlen (sv->u.s), 0, &re_regs);
@@ -585,9 +586,9 @@ docolon (VALUE *sv, VALUE *pv)
v = int_value (0);
}
else
- error (EXPR_FAILURE,
- (matchlen == -2 ? errno : EOVERFLOW),
- _("error in regular expression matcher"));
+ die (EXPR_FAILURE,
+ (matchlen == -2 ? errno : EOVERFLOW),
+ _("error in regular expression matcher"));
if (0 < re_regs.num_regs)
{
@@ -779,9 +780,9 @@ eval4 (bool evaluate)
if (evaluate)
{
if (!toarith (l) || !toarith (r))
- error (EXPR_INVALID, 0, _("non-integer argument"));
+ die (EXPR_INVALID, 0, _("non-integer argument"));
if (fxn != multiply && mpz_sgn (r->u.i) == 0)
- error (EXPR_INVALID, 0, _("division by zero"));
+ die (EXPR_INVALID, 0, _("division by zero"));
((fxn == multiply ? mpz_mul
: fxn == divide ? mpz_tdiv_q
: mpz_tdiv_r)
@@ -816,7 +817,7 @@ eval3 (bool evaluate)
if (evaluate)
{
if (!toarith (l) || !toarith (r))
- error (EXPR_INVALID, 0, _("non-integer argument"));
+ die (EXPR_INVALID, 0, _("non-integer argument"));
(fxn == plus ? mpz_add : mpz_sub) (l->u.i, l->u.i, r->u.i);
}
freev (r);
@@ -876,10 +877,10 @@ eval2 (bool evaluate)
{
error (0, errno, _("string comparison failed"));
error (0, 0, _("set LC_ALL='C' to work around the problem"));
- error (EXPR_INVALID, 0,
- _("the strings compared were %s and %s"),
- quotearg_n_style (0, locale_quoting_style, l->u.s),
- quotearg_n_style (1, locale_quoting_style, r->u.s));
+ die (EXPR_INVALID, 0,
+ _("the strings compared were %s and %s"),
+ quotearg_n_style (0, locale_quoting_style, l->u.s),
+ quotearg_n_style (1, locale_quoting_style, r->u.s));
}
}