diff --git a/Common/ListUtils.cpp b/Common/ListUtils.cpp index 20305e7872d21639099785a8d2d776655925460b..03fcf4ce5f4a3466a71bbdf356f49a81211b63fc 100644 --- a/Common/ListUtils.cpp +++ b/Common/ListUtils.cpp @@ -132,14 +132,20 @@ void List_Write(List_T * liste, int index, void *data) } } -void List_Put(List_T *liste, int index, void *data) +void List_Put(List_T * liste, int index, void *data) { - liste->n += 1; - List_Realloc(liste, liste->n); - for(int j = 0; j < liste->n -1 - index; j++) - memcpy(List_Pointer_Fast(liste, liste->n - j - 1), List_Pointer_Fast(liste, liste->n - 1 - j - 1), - liste->size); - memcpy(&liste->array[index * liste->size], data, liste->size); + if(index < 0) + Msg::Error("Wrong list index (put)"); + else { + if(index >= liste->n) { + liste->n = index + 1; + List_Realloc(liste, liste->n); + List_Write(liste, index, data); + } + else { + List_Write(liste, index, data); + } + } } void List_Pop(List_T * liste)