[asterisk-commits] vector: After remove element recheck index (asterisk[master])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Oct 11 16:41:34 CDT 2016


Anonymous Coward #1000019 has submitted this change and it was merged.

Change subject: vector: After remove element recheck index
......................................................................


vector: After remove element recheck index

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
---
M include/asterisk/vector.h
1 file changed, 9 insertions(+), 5 deletions(-)

Approvals:
  Richard Mudgett: Looks good to me, but someone else must approve
  Anonymous Coward #1000019: Verified
  Joshua Colp: Looks good to me, approved
  Corey Farrell: Looks good to me, but someone else must approve



diff --git a/include/asterisk/vector.h b/include/asterisk/vector.h
index b4a8a2c..c74f0a8 100644
--- a/include/asterisk/vector.h
+++ b/include/asterisk/vector.h
@@ -367,11 +367,13 @@
 	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;								\
@@ -417,14 +419,16 @@
 	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;								\
 })
 
 /*!
@@ -445,7 +449,7 @@
 	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;						\
 		}							\

-- 
To view, visit https://gerrit.asterisk.org/4065
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ib947fa94dc91dcd9341f357f1084782c64434eb7
Gerrit-PatchSet: 7
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Badalian Vyacheslav <v.badalyan at open-bs.ru>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Badalian Vyacheslav <v.badalyan at open-bs.ru>
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>



More information about the asterisk-commits mailing list