Try to silence a gcc warning. Also, replace the wrong-looking
VECTOR_DEFAULT_SIZE by 1 (after all, we've just deleted a single
element).

Found by Fedora's static analysis [1].

[1] 
https://openscanhub.fedoraproject.org/task/51915/log/device-mapper-multipath-0.11.1-1.fc43/scan-results.html

Signed-off-by: Martin Wilck <mwi...@suse.com>
---
 libmpathutil/vector.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/libmpathutil/vector.c b/libmpathutil/vector.c
index 7f763cb..3386651 100644
--- a/libmpathutil/vector.c
+++ b/libmpathutil/vector.c
@@ -107,28 +107,28 @@ int find_slot(vector v, const void *addr)
 void
 vector_del_slot(vector v, int slot)
 {
-       int i;
+       int i, allocated;
 
        if (!v || !v->allocated || slot < 0 || slot >= VECTOR_SIZE(v))
                return;
 
        for (i = slot + 1; i < VECTOR_SIZE(v); i++)
-               v->slot[i-1] = v->slot[i];
+               v->slot[i - 1] = v->slot[i];
 
-       v->allocated -= VECTOR_DEFAULT_SIZE;
+       allocated = v->allocated - 1;
 
-       if (v->allocated <= 0) {
+       if (allocated <= 0) {
                free(v->slot);
                v->slot = NULL;
                v->allocated = 0;
        } else {
                void *new_slot;
 
-               new_slot = realloc(v->slot, sizeof (void *) * v->allocated);
-               if (!new_slot)
-                       v->allocated += VECTOR_DEFAULT_SIZE;
-               else
+               new_slot = realloc(v->slot, sizeof(void *) * allocated);
+               if (new_slot) {
                        v->slot = new_slot;
+                       v->allocated = allocated;
+               }
        }
 }
 
-- 
2.49.0


Reply via email to