From 1401269ae41a5df5ea954460bb326d33d6d41142 Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 7 Oct 1999 19:13:05 +0000 Subject: [PATCH] fixed WMInsertInBag --- WINGs/bag.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/WINGs/bag.c b/WINGs/bag.c index a9e3f9bb..27612a51 100644 --- a/WINGs/bag.c +++ b/WINGs/bag.c @@ -74,7 +74,15 @@ WMInsertInBag(WMBag *bag, int index, void *item) bag->items = wrealloc(bag->items, sizeof(void*) * bag->size); } - bag->items[bag->count++] = item; + if (index >= 0 && index < bag->count) { + memmove(&bag->items[index+1], &bag->items[index], + (bag->count - index) * sizeof(void*)); + } else { + /* If index is invalid, place it at end */ + index = bag->count; + } + bag->items[index] = item; + bag->count++; }