diff options
author | Omar Polo <op@omarpolo.com> | 2024-06-17 07:23:18 +0000 |
---|---|---|
committer | Omar Polo <op@omarpolo.com> | 2024-06-17 07:23:18 +0000 |
commit | 0a7192ddc76de4ee32eb017306ab5971d902d638 (patch) | |
tree | 10df081c3780a10e36db6735050e5cd65e719222 | |
parent | bc5e9ae52576c9a0673dd2b7b7ddaadd05dd976e (diff) |
titan: improve error checking
Not only the reading, but the writing can fail too so bail out early
in that case. Also, even if it's just a pro forma, check the error
flag on stdin too.
-rw-r--r-- | titan.c | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -181,9 +181,10 @@ open_input_file(int argc, char **argv) r = fread(buf, 1, sizeof(buf), stdin); if (r == 0) break; - fwrite(buf, 1, r, fp); + if (fwrite(buf, 1, r, fp) != r) + break; } - if (ferror(fp)) + if (ferror(fp) || ferror(stdin)) err(1, "I/O error"); if (fseeko(fp, 0, SEEK_SET) == -1) |