From ec8c425866a164c3e73144751a5071aaf6660664 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sun, 16 Oct 2016 17:11:33 -0400 Subject: Check for errors in -print and friends. --- eval.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'eval.c') diff --git a/eval.c b/eval.c index 65a9186..d66c9f6 100644 --- a/eval.c +++ b/eval.c @@ -633,7 +633,10 @@ bool eval_print(const struct expr *expr, struct eval_state *state) { fill_statbuf(state); } - pretty_print(colors, state->ftwbuf); + if (pretty_print(colors, state->ftwbuf) != 0) { + eval_error(state); + } + return true; } @@ -642,8 +645,16 @@ bool eval_print(const struct expr *expr, struct eval_state *state) { */ bool eval_fprint(const struct expr *expr, struct eval_state *state) { const char *path = state->ftwbuf->path; - fputs(path, expr->file); - fputc('\n', expr->file); + if (fputs(path, expr->file) == EOF) { + goto error; + } + if (fputc('\n', expr->file) == EOF) { + goto error; + } + return true; + +error: + eval_error(state); return true; } @@ -652,7 +663,10 @@ bool eval_fprint(const struct expr *expr, struct eval_state *state) { */ bool eval_print0(const struct expr *expr, struct eval_state *state) { const char *path = state->ftwbuf->path; - fwrite(path, 1, strlen(path) + 1, expr->file); + size_t length = strlen(path) + 1; + if (fwrite(path, 1, length, expr->file) != length) { + eval_error(state); + } return true; } -- cgit v1.2.3