From 617e53c307e6d7c3de761a14744c50d1b250db19 Mon Sep 17 00:00:00 2001 Message-Id: <617e53c307e6d7c3de761a14744c50d1b250db19.1411497349.git.jen@redhat.com> In-Reply-To: References: From: Juan Quintela Date: Tue, 16 Sep 2014 15:50:20 -0400 Subject: [CHANGE 4/7] migration: avoid no-op memmove() of potential large buffer To: rhvirt-patches@redhat.com, jen@redhat.com RH-Author: Juan Quintela Message-id: <1410882623-10906-5-git-send-email-quintela@redhat.com> Patchwork-id: 61190 O-Subject: [PATCH qemu-kvm RHEL6.6 4/7] migration: avoid no-op memmove() of potential large buffer Bugzilla: 1142756 970103 RH-Acked-by: Dr. David Alan Gilbert (git) RH-Acked-by: Amit Shah RH-Acked-by: Markus Armbruster When buffered_flush() makes no progress, it moves the buffer onto itself. Don't. While there, also avoid empty memmove(). Signed-off-by: Juan Quintela Signed-off-by: Jeff E. Nelson --- buffered_file.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/buffered_file.c b/buffered_file.c index 424dbd1..38abbac 100644 --- a/buffered_file.c +++ b/buffered_file.c @@ -104,8 +104,10 @@ static void buffered_flush(QEMUFileBuffered *s) } DPRINTF("flushed %zu of %zu byte(s)\n", offset, s->buffer_size); - memmove(s->buffer, s->buffer + offset, s->buffer_size - offset); - s->buffer_size -= offset; + if ((offset > 0) && ((s->buffer_size - offset) > 0)) { + memmove(s->buffer, s->buffer + offset, s->buffer_size - offset); + s->buffer_size -= offset; + } } static int buffered_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, int size) -- 1.9.3