]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
vector: After remove element recheck index 67/4067/6
authorBadalyan Vyacheslav <v.badalyan@open-bs.ru>
Mon, 10 Oct 2016 21:59:58 +0000 (17:59 -0400)
committerBadalian Vyacheslav <v.badalyan@open-bs.ru>
Tue, 11 Oct 2016 11:43:34 +0000 (06:43 -0500)
Small fix. It is necessary to double-check
the index that we just removed because there
is a new element.

ASTERISK-26453 #close

Change-Id: Ib947fa94dc91dcd9341f357f1084782c64434eb7

include/asterisk/vector.h

index ef6104d57163569f957649088d8ef106d988753b..4306670e7e1c81d906eda6c7a0db839bf425f1f0 100644 (file)
        int count = 0;                                                  \
        size_t idx;                                                     \
        typeof(value) __value = (value);                                \
-       for (idx = 0; idx < (vec)->current; ++idx) {                    \
+       for (idx = 0; idx < (vec)->current; ) {                         \
                if (cmp((vec)->elems[idx], __value)) {                  \
                        cleanup((vec)->elems[idx]);                     \
                        AST_VECTOR_REMOVE_UNORDERED((vec), idx);        \
                        ++count;                                        \
+               } else {                                                \
+                       ++idx;                                          \
                }                                                       \
        }                                                               \
        count;                                                          \
        int count = 0;                                                  \
        size_t idx;                                                     \
        typeof(value) __value = (value);                                \
-       for (idx = 0; idx < (vec)->current; ++idx) {                    \
+       for (idx = 0; idx < (vec)->current; ) {                         \
                if (cmp((vec)->elems[idx], __value)) {                  \
                        cleanup((vec)->elems[idx]);                     \
-                       AST_VECTOR_REMOVE_ORDERED((vec), idx);  \
+                       AST_VECTOR_REMOVE_ORDERED((vec), idx);          \
                        ++count;                                        \
+               } else {                                                \
+                       ++idx;                                          \
                }                                                       \
        }                                                               \
-       oount;                                                          \
+       count;                                                          \
 })
 
 /*!
        for (idx = 0; idx < (vec)->current; ++idx) {                    \
                if (cmp((vec)->elems[idx], __value)) {                  \
                        cleanup((vec)->elems[idx]);                     \
-                       AST_VECTOR_REMOVE_ORDERED((vec), idx);  \
+                       AST_VECTOR_REMOVE_ORDERED((vec), idx);          \
                        res = 0;                                        \
                        break;                                          \
                }                                                       \