]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
storage: storageBackendWipeLocal: reduce variable scope
authorJán Tomko <jtomko@redhat.com>
Wed, 23 Sep 2020 17:48:19 +0000 (19:48 +0200)
committerJán Tomko <jtomko@redhat.com>
Thu, 24 Sep 2020 09:19:06 +0000 (11:19 +0200)
Also use MIN instead of open-coding it.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
src/storage/storage_util.c

index 94f62515f2a9e1ed583d587dbd57aaa9cedc464d..53d4d2a31a348ee0a3c68d64ad4004efc1a24c84 100644 (file)
@@ -2526,10 +2526,8 @@ storageBackendWipeLocal(const char *path,
                         size_t writebuf_length,
                         bool zero_end)
 {
-    int written = 0;
     unsigned long long remaining = 0;
     off_t size;
-    size_t write_size = 0;
     g_autofree char *writebuf = NULL;
 
     if (VIR_ALLOC_N(writebuf, writebuf_length) < 0)
@@ -2557,9 +2555,9 @@ storageBackendWipeLocal(const char *path,
 
     remaining = wipe_len;
     while (remaining > 0) {
+        size_t write_size = MIN(writebuf_length, remaining);
+        int written = safewrite(fd, writebuf, write_size);
 
-        write_size = (writebuf_length < remaining) ? writebuf_length : remaining;
-        written = safewrite(fd, writebuf, write_size);
         if (written < 0) {
             virReportSystemError(errno,
                                  _("Failed to write %zu bytes to "