Skip to content

Commit aa9bf44

Browse files
committed
nbio_vfprintf: improve error handling a bit
1 parent a6d8283 commit aa9bf44

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

lib/nbio.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,25 @@ nbio_vfprintf(FILE *fp, const char *fmt, va_list ap)
8585
if (ret == 1) {
8686
continue;
8787
}
88+
assert(ret == -1);
89+
if (errno == EAGAIN || errno == EINTR) {
90+
continue;
91+
}
8892
/* poll error, fall through */
8993
}
90-
if (written == 0) {
91-
/* errno is already set by write or poll */
92-
written = -1;
93-
}
94+
/* errno is already set by write or poll */
95+
written = -1;
96+
assert(errno > 0);
9497
break;
9598
}
99+
assert(0 < ssz && ssz <= len - written);
96100
written += ssz;
101+
assert(0 < written && written <= len);
97102
}
98103
int saved_errno = errno; /* just in case */
99104
funlockfile(fp);
100105
free(buf);
106+
assert(written == -1 || written == len);
101107
assert(written <= INT_MAX);
102108
assert(written >= INT_MIN);
103109
errno = saved_errno;

0 commit comments

Comments
 (0)