[Asterisk-code-review] vector: After remove element recheck index (asterisk[14])

Anonymous Coward asteriskteam at digium.com
Tue Oct 11 17:39:55 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/4066
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ib947fa94dc91dcd9341f357f1084782c64434eb7
Gerrit-PatchSet: 6
Gerrit-Project: asterisk
Gerrit-Branch: 14
Gerrit-Owner: Badalian Vyacheslav <v.badalyan at open-bs.ru>
Gerrit-Reviewer: Anonymous Coward #1000019
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-code-review mailing list