summaryrefslogtreecommitdiff
path: root/bin/ed
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2019-06-28 13:35:06 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2019-06-28 13:35:06 +0000
commit61656abc7ff84215165af1bd464bc053b3b66158 (patch)
treec7eabb0c4fa9faa024e724e99c240c40da07ca42 /bin/ed
parent18603ebf99fbb890ae9666cb0c4aa9f879e7edaa (diff)
When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?) callers of syscalls to follow this better, and let's see if this strictness helps us in the future.
Diffstat (limited to 'bin/ed')
-rw-r--r--bin/ed/buf.c17
-rw-r--r--bin/ed/main.c4
2 files changed, 10 insertions, 11 deletions
diff --git a/bin/ed/buf.c b/bin/ed/buf.c
index 14987cfcda7..06dc7ebc89c 100644
--- a/bin/ed/buf.c
+++ b/bin/ed/buf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: buf.c,v 1.23 2016/03/22 17:58:28 mmcc Exp $ */
+/* $OpenBSD: buf.c,v 1.24 2019/06/28 13:34:59 deraadt Exp $ */
/* $NetBSD: buf.c,v 1.15 1995/04/23 10:07:28 cgd Exp $ */
/* buf.c: This file contains the scratch-file buffer routines for the
@@ -55,8 +55,7 @@ get_sbuf_line(line_t *lp)
{
static char *sfbuf = NULL; /* buffer */
static int sfbufsz = 0; /* buffer size */
-
- int len, ct;
+ int len;
if (lp == &buffer_head)
return NULL;
@@ -64,7 +63,7 @@ get_sbuf_line(line_t *lp)
/* out of position */
if (sfseek != lp->seek) {
sfseek = lp->seek;
- if (fseeko(sfp, sfseek, SEEK_SET) < 0) {
+ if (fseeko(sfp, sfseek, SEEK_SET) == -1) {
perror(NULL);
seterrmsg("cannot seek temp file");
return NULL;
@@ -72,7 +71,7 @@ get_sbuf_line(line_t *lp)
}
len = lp->len;
REALLOC(sfbuf, sfbufsz, len + 1, NULL);
- if ((ct = fread(sfbuf, sizeof(char), len, sfp)) < 0 || ct != len) {
+ if (fread(sfbuf, sizeof(char), len, sfp) != len) {
perror(NULL);
seterrmsg("cannot read temp file");
return NULL;
@@ -89,7 +88,7 @@ char *
put_sbuf_line(char *cs)
{
line_t *lp;
- int len, ct;
+ int len;
char *s;
if ((lp = malloc(sizeof(line_t))) == NULL) {
@@ -108,7 +107,7 @@ put_sbuf_line(char *cs)
len = s - cs;
/* out of position */
if (seek_write) {
- if (fseek(sfp, 0L, SEEK_END) < 0) {
+ if (fseek(sfp, 0L, SEEK_END) == -1) {
perror(NULL);
seterrmsg("cannot seek temp file");
free(lp);
@@ -118,7 +117,7 @@ put_sbuf_line(char *cs)
seek_write = 0;
}
/* assert: SPL1() */
- if ((ct = fwrite(cs, sizeof(char), len, sfp)) < 0 || ct != len) {
+ if (fwrite(cs, sizeof(char), len, sfp) != len) {
sfseek = -1;
perror(NULL);
seterrmsg("cannot write temp file");
@@ -226,7 +225,7 @@ int
close_sbuf(void)
{
if (sfp) {
- if (fclose(sfp) < 0) {
+ if (fclose(sfp) == EOF) {
perror(sfn);
seterrmsg("cannot close temp file");
return ERR;
diff --git a/bin/ed/main.c b/bin/ed/main.c
index d01a3955eb3..dc73dd92b69 100644
--- a/bin/ed/main.c
+++ b/bin/ed/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.65 2018/06/15 08:45:03 martijn Exp $ */
+/* $OpenBSD: main.c,v 1.66 2019/06/28 13:34:59 deraadt Exp $ */
/* $NetBSD: main.c,v 1.3 1995/03/21 09:04:44 cgd Exp $ */
/* main.c: This file contains the main control and user-interface routines
@@ -1384,7 +1384,7 @@ handle_winch(int signo)
int save_errno = errno;
struct winsize ws; /* window size structure */
- if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) >= 0) {
+ if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == 0) {
if (ws.ws_row > 2)
rows = ws.ws_row - 2;
if (ws.ws_col > 8)