mirror of
git://erdgeist.org/opentracker
synced 2025-04-29 16:06:18 +08:00
Silence warning about using a pointer after realloc, take offset of match before
This commit is contained in:
parent
c854b3db9b
commit
123e8aa1b9
@ -68,11 +68,14 @@ void *vector_find_or_insert(ot_vector *vector, void *key, size_t member_size, si
|
|||||||
|
|
||||||
if (vector->size + 1 > vector->space) {
|
if (vector->size + 1 > vector->space) {
|
||||||
size_t new_space = vector->space ? OT_VECTOR_GROW_RATIO * vector->space : OT_VECTOR_MIN_MEMBERS;
|
size_t new_space = vector->space ? OT_VECTOR_GROW_RATIO * vector->space : OT_VECTOR_MIN_MEMBERS;
|
||||||
|
ptrdiff_t match_off = match - (uint8_t *)vector->data;
|
||||||
uint8_t *new_data = realloc(vector->data, new_space * member_size);
|
uint8_t *new_data = realloc(vector->data, new_space * member_size);
|
||||||
|
|
||||||
if (!new_data)
|
if (!new_data)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* Adjust pointer if it moved by realloc */
|
/* Adjust pointer if it moved by realloc */
|
||||||
match = new_data + (match - (uint8_t *)vector->data);
|
match = new_data + match_off;
|
||||||
|
|
||||||
vector->data = new_data;
|
vector->data = new_data;
|
||||||
vector->space = new_space;
|
vector->space = new_space;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user