diff options
author | Florian Obser <florian@cvs.openbsd.org> | 2019-06-27 06:41:37 +0000 |
---|---|---|
committer | Florian Obser <florian@cvs.openbsd.org> | 2019-06-27 06:41:37 +0000 |
commit | 21d1ccf81beb6d7a50c2137a3e28f25c89094c67 (patch) | |
tree | f13a4abef99804def54c7f9f9b6fd533a339e76a /bin | |
parent | 4a91562dc6683317f04f7573c2f7e61bd09c639c (diff) |
Be precise in checking for errors. pclose(3) returns -1 and fclose(3)
EOF in case of errors, not any negative number.
EOF corner case spotted while reviewing a much bigger diff by deraadt
OK deraadt, millert
Diffstat (limited to 'bin')
-rw-r--r-- | bin/ed/io.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/bin/ed/io.c b/bin/ed/io.c index e9d6e1c3007..673a2cad9f9 100644 --- a/bin/ed/io.c +++ b/bin/ed/io.c @@ -1,4 +1,4 @@ -/* $OpenBSD: io.c,v 1.22 2018/06/04 13:29:07 martijn Exp $ */ +/* $OpenBSD: io.c,v 1.23 2019/06/27 06:41:36 florian Exp $ */ /* $NetBSD: io.c,v 1.2 1995/03/21 09:04:43 cgd Exp $ */ /* io.c: This file contains the i/o routines for the ed line editor */ @@ -58,7 +58,7 @@ read_file(char *fn, int n) return ERR; } else if ((size = read_stream(fp, n)) < 0) return ERR; - else if (((*fn == '!') ? pclose(fp) : fclose(fp)) < 0) { + else if ((*fn == '!') ? pclose(fp) == -1 : fclose(fp) == EOF) { perror(fn); seterrmsg("cannot close input file"); return ERR; @@ -160,7 +160,7 @@ write_file(char *fn, char *mode, int n, int m) return ERR; } else if ((size = write_stream(fp, n, m)) < 0) return ERR; - else if (((*fn == '!') ? pclose(fp) : fclose(fp)) < 0) { + else if ((*fn == '!') ? pclose(fp) == -1 : fclose(fp) == EOF) { perror(fn); seterrmsg("cannot close output file"); return ERR; |