tdb: add a 'new_size' helper variable to tdb_expand_file()
authorStefan Metzmacher <metze@samba.org>
Tue, 28 May 2013 10:56:57 +0000 (12:56 +0200)
committerVolker Lendecke <vl@samba.org>
Mon, 3 Jun 2013 08:21:22 +0000 (10:21 +0200)
Pair-Programmed-With: Volker Lendecke <vl@samba.org>

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Rusty Russell <rusty@rustcorp.com.au>
lib/tdb/common/io.c

index a477fb55e4b1f4e1cc74cf90aa1e60e38c1771b6..44ef7289a6395c10a64ec3cfb9b12e2587b261d6 100644 (file)
@@ -287,18 +287,21 @@ int tdb_mmap(struct tdb_context *tdb)
 static int tdb_expand_file(struct tdb_context *tdb, tdb_off_t size, tdb_off_t addition)
 {
        char buf[8192];
+       tdb_off_t new_size;
 
        if (tdb->read_only || tdb->traverse_read) {
                tdb->ecode = TDB_ERR_RDONLY;
                return -1;
        }
 
-       if (ftruncate(tdb->fd, size+addition) == -1) {
+       new_size = size + addition;
+
+       if (ftruncate(tdb->fd, new_size) == -1) {
                char b = 0;
-               ssize_t written = pwrite(tdb->fd,  &b, 1, (size+addition) - 1);
+               ssize_t written = pwrite(tdb->fd,  &b, 1, new_size - 1);
                if (written == 0) {
                        /* try once more, potentially revealing errno */
-                       written = pwrite(tdb->fd,  &b, 1, (size+addition) - 1);
+                       written = pwrite(tdb->fd,  &b, 1, new_size - 1);
                }
                if (written == 0) {
                        /* again - give up, guessing errno */
@@ -306,7 +309,7 @@ static int tdb_expand_file(struct tdb_context *tdb, tdb_off_t size, tdb_off_t ad
                }
                if (written != 1) {
                        TDB_LOG((tdb, TDB_DEBUG_FATAL, "expand_file to %u failed (%s)\n",
-                                size+addition, strerror(errno)));
+                                (unsigned)new_size, strerror(errno)));
                        return -1;
                }
        }