diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2016-10-16 17:11:33 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2016-10-16 17:11:33 -0400 |
commit | ec8c425866a164c3e73144751a5071aaf6660664 (patch) | |
tree | 4dc98f6ef5d24d78b4577ed48a3039f07c2ba945 /eval.c | |
parent | b2175be362b0a32d06d98369302d55b226b58ab1 (diff) | |
download | bfs-ec8c425866a164c3e73144751a5071aaf6660664.tar.xz |
Check for errors in -print and friends.
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 22 |
1 files changed, 18 insertions, 4 deletions
@@ -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; } |