Commit b72a2ee1 authored by Rusty Russell's avatar Rusty Russell

tdb2: fix pread/pwrite error handling in fill and tdb_write.

The "ret < n" was done as an unsigned comparison, so it didn't work as
expected when ret was negative.

Simplest fix is to do an equals comparison everywhere, which is also
slightly stricter.
parent a39bf3ac
......@@ -246,7 +246,7 @@ static enum TDB_ERROR tdb_write(struct tdb_context *tdb, tdb_off_t off,
} else {
ssize_t ret;
ret = pwrite(tdb->fd, buf, len, off);
if (ret < len) {
if (ret != len) {
/* This shouldn't happen: we avoid sparse files. */
if (ret >= 0)
errno = ENOSPC;
......@@ -375,7 +375,7 @@ static enum TDB_ERROR fill(struct tdb_context *tdb,
while (len) {
size_t n = len > size ? size : len;
ssize_t ret = pwrite(tdb->fd, buf, n, off);
if (ret < n) {
if (ret != n) {
if (ret >= 0)
errno = ENOSPC;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment