Received: from eggs.gnu.org ([2001:4830:134:3::10]:36257) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bUfXx-0007K7-6E for qemu-devel@nongnu.org; Tue, 02 Aug 2016 15:40:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bUfXv-0003nM-G0 for qemu-devel@nongnu.org; Tue, 02 Aug 2016 15:40:12 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:33633) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bUfXv-0003mm-8y for qemu-devel@nongnu.org; Tue, 02 Aug 2016 15:40:11 -0400 Received: by mail-wm0-x242.google.com with SMTP id o80so32558191wme.0 for ; Tue, 02 Aug 2016 12:40:11 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Tue, 2 Aug 2016 21:39:35 +0200 Message-Id: <1470166775-3671-26-git-send-email-pbonzini@redhat.com> In-Reply-To: <1470166775-3671-1-git-send-email-pbonzini@redhat.com> References: <1470166775-3671-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PULL 25/25] util: Fix assertion in iov_copy() upon zero 'bytes' and non-zero 'offset' List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Shmulik Ladkani From: Shmulik Ladkani 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 Message-Id: <1470130880-1050-1-git-send-email-shmulik.ladkani@oracle.com> Signed-off-by: Paolo Bonzini --- util/iov.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/util/iov.c b/util/iov.c index 003fcce..74e6ca8 100644 --- a/util/iov.c +++ b/util/iov.c @@ -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; -- 2.7.4