summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ot_vector.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/ot_vector.c b/ot_vector.c
index 2bc07b5..2acfbef 100644
--- a/ot_vector.c
+++ b/ot_vector.c
@@ -67,12 +67,15 @@ void *vector_find_or_insert(ot_vector *vector, void *key, size_t member_size, si
67 return match; 67 return match;
68 68
69 if (vector->size + 1 > vector->space) { 69 if (vector->size + 1 > vector->space) {
70 size_t new_space = vector->space ? OT_VECTOR_GROW_RATIO * vector->space : OT_VECTOR_MIN_MEMBERS; 70 size_t new_space = vector->space ? OT_VECTOR_GROW_RATIO * vector->space : OT_VECTOR_MIN_MEMBERS;
71 uint8_t *new_data = realloc(vector->data, new_space * member_size); 71 ptrdiff_t match_off = match - (uint8_t *)vector->data;
72 uint8_t *new_data = realloc(vector->data, new_space * member_size);
73
72 if (!new_data) 74 if (!new_data)
73 return NULL; 75 return NULL;
76
74 /* Adjust pointer if it moved by realloc */ 77 /* Adjust pointer if it moved by realloc */
75 match = new_data + (match - (uint8_t *)vector->data); 78 match = new_data + match_off;
76 79
77 vector->data = new_data; 80 vector->data = new_data;
78 vector->space = new_space; 81 vector->space = new_space;