[libvirt PATCH 13/14] storage: storageBackendWipeLocal: reduce variable scope

Martin Kletzander mkletzan at redhat.com
Thu Sep 24 08:42:46 UTC 2020


On Wed, Sep 23, 2020 at 08:15:02PM +0200, Ján Tomko wrote:
>Also use MIN instead of open-coding it.
>
>Signed-off-by: Ján Tomko <jtomko at redhat.com>

Reviewed-by: Martin Kletzander <mkletzan at redhat.com>

>---
> src/storage/storage_util.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
>diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c
>index 49ecbc5344..23632fc884 100644
>--- a/src/storage/storage_util.c
>+++ b/src/storage/storage_util.c
>@@ -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 "
>-- 
>2.26.2
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20200924/ad5ac1b1/attachment-0001.sig>


More information about the libvir-list mailing list