[Libguestfs] [nbdkit PATCH 06/10] streaming: Avoid -Wshadow warnings

Eric Blake eblake at redhat.com
Sun Sep 1 02:29:43 UTC 2019


Renaming variables is easy enough here. While at it, use a static
buffer rather than wasting time on memset().

Signed-off-by: Eric Blake <eblake at redhat.com>
---
 plugins/streaming/streaming.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/plugins/streaming/streaming.c b/plugins/streaming/streaming.c
index 4ab73b8b..b2359540 100644
--- a/plugins/streaming/streaming.c
+++ b/plugins/streaming/streaming.c
@@ -185,21 +185,19 @@ streaming_pwrite (void *handle, const void *buf,

   /* Need to write some zeroes. */
   if (offset > highestwrite) {
-    int64_t size = offset - highestwrite;
-    char buf[4096];
+    int64_t remaining = offset - highestwrite;
+    static char zerobuf[4096];

-    memset (buf, 0, sizeof buf);
-
-    while (size > 0) {
-      n = size > sizeof buf ? sizeof buf : size;
-      r = write (fd, buf, n);
+    while (remaining > 0) {
+      n = remaining > sizeof zerobuf ? sizeof zerobuf : remaining;
+      r = write (fd, zerobuf, n);
       if (r == -1) {
         nbdkit_error ("write: %m");
         errorstate = 1;
         return -1;
       }
       highestwrite += r;
-      size -= r;
+      remaining -= r;
     }
   }

-- 
2.21.0




More information about the Libguestfs mailing list