]> git.ipfire.org Git - thirdparty/opentracker.git/commitdiff
Silence warning about using a pointer after realloc, take offset of match before
authorDirk Engling <erdgeist@erdgeist.org>
Fri, 25 Apr 2025 19:49:53 +0000 (21:49 +0200)
committerDirk Engling <erdgeist@erdgeist.org>
Fri, 25 Apr 2025 19:49:53 +0000 (21:49 +0200)
ot_vector.c

index 2bc07b5fb0de29c048f2849abf4a02848585423e..2acfbef67c5e7aa55d010ea43d82f545cb0e3042 100644 (file)
@@ -67,12 +67,15 @@ void *vector_find_or_insert(ot_vector *vector, void *key, size_t member_size, si
     return match;
 
   if (vector->size + 1 > vector->space) {
-    size_t   new_space = vector->space ? OT_VECTOR_GROW_RATIO * vector->space : OT_VECTOR_MIN_MEMBERS;
-    uint8_t *new_data  = realloc(vector->data, new_space * member_size);
+    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);
+
     if (!new_data)
       return NULL;
+
     /* 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->space = new_space;