]> git.proxmox.com Git - mirror_qemu.git/commitdiff
util: Fix assertion in iov_copy() upon zero 'bytes' and non-zero 'offset'
authorShmulik Ladkani <shmulik.ladkani@ravellosystems.com>
Tue, 2 Aug 2016 09:41:20 +0000 (12:41 +0300)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 3 Aug 2016 16:44:57 +0000 (18:44 +0200)
In cases where iov_copy() is passed with zero 'bytes' argument and a
non-zero 'offset' argument, nothing gets copied - as expected.

However no copy iterations are performed, so 'offset' is left
unaltered, leading to the final assert(offset == 0) to fail.

Instead, change the loop condition to continue as long as 'offset || bytes',
similar to other iov_* functions.

This ensures 'offset' gets zeroed (even if no actual copy is made),
unless it is beyond end of source iov - which is asserted.

Signed-off-by: Shmulik Ladkani <shmulik.ladkani@ravellosystems.com>
Message-Id: <1470130880-1050-1-git-send-email-shmulik.ladkani@oracle.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
util/iov.c

index 003fcce66f21c5028de0a2cf028981effefe4e37..74e6ca8ed7298c833e52257923c10fb73c9377ad 100644 (file)
@@ -247,7 +247,8 @@ unsigned iov_copy(struct iovec *dst_iov, unsigned int dst_iov_cnt,
 {
     size_t len;
     unsigned int i, j;
-    for (i = 0, j = 0; i < iov_cnt && j < dst_iov_cnt && bytes; i++) {
+    for (i = 0, j = 0;
+         i < iov_cnt && j < dst_iov_cnt && (offset || bytes); i++) {
         if (offset >= iov[i].iov_len) {
             offset -= iov[i].iov_len;
             continue;