fix ArrayList_Shift for args (al, 0, -1)

As a result, this should fix #1051.
This commit is contained in:
Christian Hofstaedtler 2013-03-07 12:43:10 +01:00
parent 06e7d73daf
commit 8833c14eac
2 changed files with 24 additions and 2 deletions

View File

@ -148,7 +148,7 @@ void ArrayList_Shift(wArrayList* arrayList, int index, int count)
} }
else if (count < 0) else if (count < 0)
{ {
MoveMemory(&arrayList->array[index + count], &arrayList->array[index], (arrayList->size - index) * sizeof(void*)); MoveMemory(&arrayList->array[index], &arrayList->array[index - count], (arrayList->size + count) * sizeof(void*));
arrayList->size += count; arrayList->size += count;
} }
} }

View File

@ -7,11 +7,13 @@ int TestArrayList(int argc, char* argv[])
{ {
int index; int index;
int count; int count;
size_t val;
wArrayList* arrayList; wArrayList* arrayList;
const int elemsToInsert = 10;
arrayList = ArrayList_New(TRUE); arrayList = ArrayList_New(TRUE);
for (index = 0; index < 10; index++) for (index = 0; index < elemsToInsert; index++)
{ {
ArrayList_Add(arrayList, (void*) (size_t) index); ArrayList_Add(arrayList, (void*) (size_t) index);
} }
@ -43,6 +45,26 @@ int TestArrayList(int argc, char* argv[])
if (index != 6) if (index != 6)
return -1; return -1;
for (index = 0; index < elemsToInsert; index++) {
val = (size_t)ArrayList_GetItem(arrayList, 0);
ArrayList_RemoveAt(arrayList, 0);
if (val != index)
{
printf("ArrayList: shifted %d entries, expected value %d, got %d\n", index, index, val);
return -1;
}
}
index = ArrayList_IndexOf(arrayList, (void*) (size_t) elemsToInsert, -1, -1);
printf("ArrayList index: %d\n", index);
if (index != -1)
return -1;
count = ArrayList_Count(arrayList);
printf("ArrayList count: %d\n", count);
if (count != 0)
return -1;
ArrayList_Clear(arrayList); ArrayList_Clear(arrayList);
ArrayList_Free(arrayList); ArrayList_Free(arrayList);