From 90b2f5aff86d1d22816831b4441f1c2aa482e726 Mon Sep 17 00:00:00 2001 From: Greg King Date: Sat, 2 Jul 2016 10:26:33 -0400 Subject: [PATCH] Fixed some code that adjusts an index after a deletion from a collection. --- src/common/coll.c | 13 +++++++------ src/common/coll.h | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/common/coll.c b/src/common/coll.c index aa2aa6470..8fb702bdc 100644 --- a/src/common/coll.c +++ b/src/common/coll.c @@ -161,7 +161,7 @@ void CollAppend (Collection* C, void* Item) { /* Insert the item at the end of the current list */ CollInsert (C, Item, C->Count); -} +} #endif @@ -341,22 +341,23 @@ void CollReplaceExpand (Collection* C, void* Item, unsigned Index) void CollMove (Collection* C, unsigned OldIndex, unsigned NewIndex) /* Move an item from one position in the collection to another. OldIndex -** is the current position of the item, NewIndex is the new index after +** is the current position of the item, NewIndex is the new index before ** the function has done it's work. Existing entries with indices NewIndex -** and up are moved one position upwards. +** and up might be moved one position upwards. */ { - /* Get the item and remove it from the collection */ + /* Get the item; and, remove it from the collection */ void* Item = CollAt (C, OldIndex); + CollDelete (C, OldIndex); /* Correct NewIndex if needed */ - if (NewIndex >= OldIndex) { + if (NewIndex > OldIndex) { /* Position has changed with removal */ --NewIndex; } - /* Now insert it at the new position */ + /* Now, insert it at the new position */ CollInsert (C, Item, NewIndex); } diff --git a/src/common/coll.h b/src/common/coll.h index 5114862c4..99e337d7a 100644 --- a/src/common/coll.h +++ b/src/common/coll.h @@ -268,9 +268,9 @@ void CollReplaceExpand (Collection* C, void* Item, unsigned Index); void CollMove (Collection* C, unsigned OldIndex, unsigned NewIndex); /* Move an item from one position in the collection to another. OldIndex -** is the current position of the item, NewIndex is the new index after +** is the current position of the item, NewIndex is the new index before ** the function has done it's work. Existing entries with indices NewIndex -** and up are moved one position upwards. +** and up might be moved one position upwards. */ void CollMoveMultiple (Collection* C, unsigned Start, unsigned Count, unsigned Target); -- 2.39.5