diff options
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/helpers.c | 4 | ||||
-rw-r--r-- | Alc/vector.h | 4 |
2 files changed, 5 insertions, 3 deletions
diff --git a/Alc/helpers.c b/Alc/helpers.c index 2fbb588b..97f7988e 100644 --- a/Alc/helpers.c +++ b/Alc/helpers.c @@ -796,14 +796,16 @@ ALboolean vector_resize(void *ptr, size_t base_size, size_t obj_count, size_t ob return AL_TRUE; } -ALboolean vector_insert(void *ptr, size_t base_size, size_t obj_size, ptrdiff_t ins_elem, const void *datstart, const void *datend) +ALboolean vector_insert(void *ptr, size_t base_size, size_t obj_size, void *ins_pos, const void *datstart, const void *datend) { vector_ *vecptr = ptr; if(datstart != datend) { + ptrdiff_t ins_elem = ((char*)ins_pos - ((char*)(*vecptr) + base_size)) / obj_size; ptrdiff_t numins = ((const char*)datend - (const char*)datstart) / obj_size; if(!vector_reserve(vecptr, base_size, VECTOR_SIZE(*vecptr)+numins, obj_size, AL_TRUE)) return AL_FALSE; + /* NOTE: ins_pos may have been invalidated if *vecptr moved. Use ins_elem instead. */ if(ins_elem < (*vecptr)->Size) { memmove((char*)(*vecptr) + base_size + ((ins_elem+numins)*obj_size), diff --git a/Alc/vector.h b/Alc/vector.h index 7f3d769c..d12b8ad1 100644 --- a/Alc/vector.h +++ b/Alc/vector.h @@ -35,8 +35,8 @@ ALboolean vector_resize(void *ptr, size_t base_size, size_t obj_count, size_t ob #define VECTOR_ITER_BEGIN(_x) ((_x)->Data) #define VECTOR_ITER_END(_x) ((_x)->Data + VECTOR_SIZE((_x))) -ALboolean vector_insert(void *ptr, size_t base_size, size_t obj_size, ptrdiff_t ins_elem, const void *datstart, const void *datend); -#define VECTOR_INSERT(_x, _i, _s, _e) (vector_insert(&(_x), sizeof(*(_x)), sizeof((_x)->Data[0]), (_i)-VECTOR_ITER_BEGIN(_x), (_s), (_e))) +ALboolean vector_insert(void *ptr, size_t base_size, size_t obj_size, void *ins_pos, const void *datstart, const void *datend); +#define VECTOR_INSERT(_x, _i, _s, _e) (vector_insert(&(_x), sizeof(*(_x)), sizeof((_x)->Data[0]), (_i), (_s), (_e))) #define VECTOR_PUSH_BACK(_x, _obj) (vector_reserve(&(_x), sizeof(*(_x)), VECTOR_SIZE(_x)+1, sizeof((_x)->Data[0]), AL_FALSE) && \ (((_x)->Data[(_x)->Size++] = (_obj)),AL_TRUE)) |