Skip to content

Commit

Permalink
Better detection of I/O errors (#1566)
Browse files Browse the repository at this point in the history
It is possible for fprintf to have flushed the stream already, in which
case fflush will succeed.  Use ferror() to catch that.

Fixes 95a8333.
  • Loading branch information
DemiMarie authored Mar 15, 2021
1 parent 23770e1 commit 23f1166
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/poptALL.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,11 @@ static void rpmcliAllArgCallback( poptContext con,
{ char *val = NULL;
if (rpmExpandMacros(NULL, arg, &val, 0) < 0)
exit(EXIT_FAILURE);
fprintf(stdout, "%s\n", val);
if (fflush(stdout) == EOF) {
if (fprintf(stdout, "%s\n", val) < 0 ||
fflush(stdout) == EOF ||
ferror(stdout)) {
perror(_("Error writing to stdout"));
free(val);
exit(EXIT_FAILURE);
}
free(val);
Expand Down

0 comments on commit 23f1166

Please sign in to comment.