[PATCH] Don't use overlapping memcpy in heapextract.

Mark Wielaard (via Code Review) gerrit at gerrit.libreoffice.org
Sat Jun 8 15:13:47 PDT 2013


I have submitted a patch for review:


To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/libexttextcat refs/changes/02/4202/1

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
M src/fingerprint.c
1 file changed, 2 insertions(+), 1 deletion(-)

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 @@
     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);

To view, visit https://gerrit.libreoffice.org/4202
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I20852eed68aaf956c8597442a986d37ff21e106a
Gerrit-PatchSet: 1
Gerrit-Project: libexttextcat
Gerrit-Branch: master
Gerrit-Owner: Mark Wielaard <mark at klomp.org>

More information about the LibreOffice mailing list