summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2013-06-08 23:57:16 +0200
committerDavid Tardon <dtardon@redhat.com>2013-06-10 05:02:01 +0000
commit18b843fccda2ba452673290965dfe69ff8ce6445 (patch)
tree268edd2a869493986550fd668ce5c59377942b9e
parent1cee75488205c82e33360ea3c9656e880919e372 (diff)
Don't use overlapping memcpy in heapextract.
Calling memcpy with source and destination overlapping might result in unexpected results. In this case it was also useless since it was trying to copy an element that was going to be removed immediately afterwards. Change-Id: I20852eed68aaf956c8597442a986d37ff21e106a Reviewed-on: https://gerrit.libreoffice.org/4202 Reviewed-by: David Tardon <dtardon@redhat.com> Tested-by: David Tardon <dtardon@redhat.com>
-rw-r--r--src/fingerprint.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/fingerprint.c b/src/fingerprint.c
index e17d83e..428b8df 100644
--- a/src/fingerprint.c
+++ b/src/fingerprint.c
@@ -254,7 +254,8 @@ static int heapextract(table_t * t, entry_t * item)
p = &(t->heap[0]);
memcpy(item, p, sizeof(entry_t));
- memcpy(&(t->heap[0]), &(t->heap[t->size - 1]), sizeof(entry_t));
+ if (t->size > 1)
+ memcpy(&(t->heap[0]), &(t->heap[t->size - 1]), sizeof(entry_t));
siftdown(t, t->size, 0);
t->size--;