From: Rusty Russell Date: Tue, 1 Mar 2011 12:49:18 +0000 (+1030) Subject: tdb2: fix pread/pwrite error handling in fill and tdb_write. X-Git-Url: https://git.ozlabs.org/?p=ccan;a=commitdiff_plain;h=b72a2ee12f033abd049111d90a2066b1151bc25d;ds=sidebyside 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. --- diff --git a/ccan/tdb2/io.c b/ccan/tdb2/io.c index 866ff085..11914b3c 100644 --- a/ccan/tdb2/io.c +++ b/ccan/tdb2/io.c @@ -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;