From mboxrd@z Thu Jan 1 00:00:00 1970 From: Benjamin Marzinski Subject: [PATCH 01/16] libmultipath: make vector_foreach_slot_backwards work as expected Date: Fri, 2 Aug 2019 11:33:27 -0500 Message-ID: <1564763622-31752-2-git-send-email-bmarzins@redhat.com> References: <1564763622-31752-1-git-send-email-bmarzins@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1564763622-31752-1-git-send-email-bmarzins@redhat.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com To: Christophe Varoqui Cc: device-mapper development , Martin Wilck , Muneendra Kumar List-Id: dm-devel.ids All of the code that uses vector_foreach_slot_backwards() treats "i" as the index of the entry "p", but the way it was coded, that wasn't the case. "i" was the number of the entry counting from 1, not 0. Signed-off-by: Benjamin Marzinski --- libmultipath/vector.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libmultipath/vector.h b/libmultipath/vector.h index 41d2b896..344dffd5 100644 --- a/libmultipath/vector.h +++ b/libmultipath/vector.h @@ -40,7 +40,7 @@ typedef struct _vector *vector; #define vector_foreach_slot_after(v,p,i) \ for (; (v) && i < VECTOR_SIZE(v) && ((p) = (v)->slot[i]); i++) #define vector_foreach_slot_backwards(v,p,i) \ - for (i = VECTOR_SIZE(v); i > 0 && ((p) = (v)->slot[i-1]); i--) + for (i = VECTOR_SIZE(v) - 1; (int)i >= 0 && ((p) = (v)->slot[i]); i--) #define identity(x) (x) /* -- 2.17.2