diff options
author | Dmitrij D. Czarkoff <czarkoff@gmail.com> | 2016-10-09 03:14:37 +0200 |
---|---|---|
committer | Dmitrij D. Czarkoff <czarkoff@gmail.com> | 2016-10-09 03:14:37 +0200 |
commit | f33b1a4a966e612a563ef761fdb55ef25e67136b (patch) | |
tree | ff3a8c53ad5d9065e65778eceb37a3c84066060c /doc | |
parent | e4ded04c39a2ceca64d390b7aa998e7537cf6a2c (diff) | |
download | imv-f33b1a4a966e612a563ef761fdb55ef25e67136b.tar.gz |
Be more correct in read_from_stdin()
From read(2) manual page on OpenBSD:
Error checks should explicitly test for -1. Code such as
while ((nr = read(fd, buf, sizeof(buf))) > 0)
is not maximally portable, as some platforms allow for nbytes to range
between SSIZE_MAX and SIZE_MAX - 2, in which case the return value of an
error-free read() may appear as a negative number distinct from -1.
Proper loops should use
while ((nr = read(fd, buf, sizeof(buf))) != -1 && nr != 0)
Distingushing between error and eof would also help for debugging.
Diffstat (limited to 'doc')
0 files changed, 0 insertions, 0 deletions