summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2017-02-07 23:01:13 -0500
committerTavian Barnes <tavianator@tavianator.com>2017-02-07 23:47:43 -0500
commit3c70db383ca48857c3bf7ed6f607c8c87fa366d9 (patch)
tree6c293bdb44f15324403f8a71688ba6038c75838f
parentaba099bbca9d73215affd49895a391e7eded0a4a (diff)
downloadbfs-3c70db383ca48857c3bf7ed6f607c8c87fa366d9.tar.xz
Add some missing perror() calls
-rw-r--r--eval.c36
-rw-r--r--parse.c32
-rw-r--r--printf.c5
3 files changed, 39 insertions, 34 deletions
diff --git a/eval.c b/eval.c
index 7ca9aa8..6109d44 100644
--- a/eval.c
+++ b/eval.c
@@ -293,16 +293,13 @@ static const char *exec_format_path(const struct expr *expr, const struct BFTW *
// For compatibility with GNU find, use './name' instead of just 'name'
char *path = dstralloc(2 + strlen(name));
if (!path) {
- perror("dstralloc()");
return NULL;
}
if (dstrcat(&path, "./") != 0) {
- perror("dstrcat()");
goto err;
}
if (dstrcat(&path, name) != 0) {
- perror("dstrcat()");
goto err;
}
@@ -327,18 +324,15 @@ static char *exec_format_arg(char *arg, const char *path) {
char *ret = dstralloc(0);
if (!ret) {
- perror("dstralloc()");
return NULL;
}
char *last = arg;
do {
if (dstrncat(&ret, last, match - last) != 0) {
- perror("dstrncat()");
goto err;
}
if (dstrcat(&ret, path) != 0) {
- perror("dstrcat()");
goto err;
}
@@ -347,7 +341,6 @@ static char *exec_format_arg(char *arg, const char *path) {
} while (match);
if (dstrcat(&ret, last) != 0) {
- perror("dstrcat()");
goto err;
}
@@ -428,6 +421,7 @@ bool eval_exec(const struct expr *expr, struct eval_state *state) {
const char *path = exec_format_path(expr, ftwbuf);
if (!path) {
+ eval_error(state);
goto out;
}
@@ -435,6 +429,7 @@ bool eval_exec(const struct expr *expr, struct eval_state *state) {
char **template = expr->argv + 1;
char **argv = exec_format_argv(argc, template, path);
if (!argv) {
+ eval_error(state);
goto out_path;
}
@@ -458,12 +453,12 @@ bool eval_exec(const struct expr *expr, struct eval_state *state) {
pid_t pid = fork();
if (pid < 0) {
- perror("fork()");
+ eval_error(state);
goto out_argv;
} else if (pid > 0) {
int status;
if (waitpid(pid, &status, 0) < 0) {
- perror("waitpid()");
+ eval_error(state);
goto out_argv;
}
@@ -801,19 +796,20 @@ bool eval_regex(const struct expr *expr, struct eval_state *state) {
int err = regexec(expr->regex, path, 1, &match, flags);
if (err == 0) {
return match.rm_so == 0 && match.rm_eo == len;
- } else {
- if (err != REG_NOMATCH) {
- char *str = xregerror(err, expr->regex);
- if (str) {
- pretty_error(state->cmdline->stderr_colors,
- "'%s': %s\n", path, str);
- free(str);
- } else {
- perror("xregerror()");
- }
+ } else if (err != REG_NOMATCH) {
+ char *str = xregerror(err, expr->regex);
+ if (str) {
+ pretty_error(state->cmdline->stderr_colors,
+ "'%s': %s\n", path, str);
+ free(str);
+ } else {
+ perror("xregerror()");
}
- return false;
+
+ *state->ret = -1;
}
+
+ return false;
}
/**
diff --git a/parse.c b/parse.c
index b2a4cc3..2224405 100644
--- a/parse.c
+++ b/parse.c
@@ -91,21 +91,24 @@ static void free_expr(struct expr *expr) {
*/
static struct expr *new_expr(eval_fn *eval, bool pure, size_t argc, char **argv) {
struct expr *expr = malloc(sizeof(struct expr));
- if (expr) {
- expr->eval = eval;
- expr->lhs = NULL;
- expr->rhs = NULL;
- expr->pure = pure;
- expr->evaluations = 0;
- expr->successes = 0;
- expr->elapsed.tv_sec = 0;
- expr->elapsed.tv_nsec = 0;
- expr->argc = argc;
- expr->argv = argv;
- expr->file = NULL;
- expr->regex = NULL;
- expr->printf = NULL;
+ if (!expr) {
+ perror("malloc()");
+ return NULL;
}
+
+ expr->eval = eval;
+ expr->lhs = NULL;
+ expr->rhs = NULL;
+ expr->pure = pure;
+ expr->evaluations = 0;
+ expr->successes = 0;
+ expr->elapsed.tv_sec = 0;
+ expr->elapsed.tv_nsec = 0;
+ expr->argc = argc;
+ expr->argv = argv;
+ expr->file = NULL;
+ expr->regex = NULL;
+ expr->printf = NULL;
return expr;
}
@@ -2471,6 +2474,7 @@ static int parse_gettime(struct timespec *ts) {
struct cmdline *parse_cmdline(int argc, char *argv[]) {
struct cmdline *cmdline = malloc(sizeof(struct cmdline));
if (!cmdline) {
+ perror("malloc()");
goto fail;
}
diff --git a/printf.c b/printf.c
index 08522db..0977d5e 100644
--- a/printf.c
+++ b/printf.c
@@ -466,6 +466,7 @@ static int append_literal(struct bfs_printf_directive ***tail, char **literal, b
struct bfs_printf *parse_bfs_printf(const char *format, const struct colors *stderr_colors) {
struct bfs_printf *command = malloc(sizeof(*command));
if (!command) {
+ perror("malloc()");
return NULL;
}
@@ -474,6 +475,10 @@ struct bfs_printf *parse_bfs_printf(const char *format, const struct colors *std
struct bfs_printf_directive **tail = &command->directives;
char *literal = dstralloc(0);
+ if (!literal) {
+ perror("dstralloc()");
+ goto error;
+ }
for (const char *i = format; *i; ++i) {
char c = *i;