]> git.ozlabs.org Git - ccan/commitdiff
tdb2: fix pread/pwrite error handling in fill and tdb_write.
authorRusty Russell <rusty@rustcorp.com.au>
Tue, 1 Mar 2011 12:49:18 +0000 (23:19 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 1 Mar 2011 12:49:18 +0000 (23:19 +1030)
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.

ccan/tdb2/io.c

index 866ff085bb5e87b6e3463e016aa7202e800c4708..11914b3c76b639f63e89442758e259b21aeeb5fe 100644 (file)
@@ -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;