Browse Source

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.
Rusty Russell 15 years ago
parent
commit
b72a2ee12f
1 changed files with 2 additions and 2 deletions
  1. 2 2
      ccan/tdb2/io.c

+ 2 - 2
ccan/tdb2/io.c

@@ -246,7 +246,7 @@ static enum TDB_ERROR tdb_write(struct tdb_context *tdb, tdb_off_t off,
 	} else {
 	} else {
 		ssize_t ret;
 		ssize_t ret;
 		ret = pwrite(tdb->fd, buf, len, off);
 		ret = pwrite(tdb->fd, buf, len, off);
-		if (ret < len) {
+		if (ret != len) {
 			/* This shouldn't happen: we avoid sparse files. */
 			/* This shouldn't happen: we avoid sparse files. */
 			if (ret >= 0)
 			if (ret >= 0)
 				errno = ENOSPC;
 				errno = ENOSPC;
@@ -375,7 +375,7 @@ static enum TDB_ERROR fill(struct tdb_context *tdb,
 	while (len) {
 	while (len) {
 		size_t n = len > size ? size : len;
 		size_t n = len > size ? size : len;
 		ssize_t ret = pwrite(tdb->fd, buf, n, off);
 		ssize_t ret = pwrite(tdb->fd, buf, n, off);
-		if (ret < n) {
+		if (ret != n) {
 			if (ret >= 0)
 			if (ret >= 0)
 				errno = ENOSPC;
 				errno = ENOSPC;