Commit ed27dafa authored by Chris Müller's avatar Chris Müller

lib: fix memmove commands for insert- and remove in arrays.

lib: insert uses now an return_code for correct indexes.
parent 434a1974
......@@ -120,18 +120,23 @@ cry_array_append(struct CryArray* array, pointer data, size_t size)
}
void
return_code
cry_array_insert(struct CryArray* array, size_t index, pointer data, size_t size)
{
assert(array != 0);
if(index > array->length)
return CRY_OUT_OF_INDEX_RANGE;
if(array->alloc < array->length + size)
cry_array_increase_alloc(array, array->length + size);
memmove(array->data + index + size, array->data + index, size);
memmove(array->data + index + size, array->data + index, array->length - index);
memcpy(array->data + index, data, size);
array->length += size;
return CRY_OKAY;
}
......@@ -144,7 +149,7 @@ cry_array_remove(struct CryArray* array, size_t index, size_t size)
if(index > array->length)
return CRY_OUT_OF_INDEX_RANGE;
memmove(array->data + index + size, array->data + index, array->length - index - size);
memmove(array->data + index, array->data + index + size, array->length - index - size);
array->length -= size;
......
......@@ -45,7 +45,7 @@ size_t cry_array_increase_alloc(struct CryArray* array, size_t
size_t cry_array_reduce_alloc(struct CryArray* array);
void cry_array_append(struct CryArray* array, pointer data, size_t size);
void cry_array_insert(struct CryArray* array, size_t index, pointer data, size_t size);
return_code cry_array_insert(struct CryArray* array, size_t index, pointer data, size_t size);
return_code cry_array_remove(struct CryArray* array, size_t index, size_t size);
pointer cry_array_get(struct CryArray* array, size_t index);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment