From f488c5b7bc5c0f003674f6f596d2452f6994c0cc Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Sat, 17 Dec 2016 22:41:11 +0800 Subject: [PATCH] igmp: Fix optimized code for igmp_remove_group The code in the for loop checks tmp_group->next == group, so current code actually checks from the 3rd entry in the linked groups list. Fix it. Fixes: 5c1dd6a4c65b ("Optimization in igmp_remove_group() pointed out by Axel Lin") Signed-off-by: Axel Lin --- src/core/ipv4/igmp.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/core/ipv4/igmp.c b/src/core/ipv4/igmp.c index 58613d3b..561448e0 100644 --- a/src/core/ipv4/igmp.c +++ b/src/core/ipv4/igmp.c @@ -295,15 +295,10 @@ static err_t igmp_remove_group(struct netif* netif, struct igmp_group *group) { err_t err = ERR_OK; - struct igmp_group *tmp_group = netif_igmp_data(netif); + struct igmp_group *tmp_group; /* Skip the first group in the list, it is always the allsystems group added in igmp_start() */ - if(tmp_group != NULL) { - tmp_group = tmp_group->next; - } - - /* look for group further down the list */ - for (; tmp_group != NULL; tmp_group = tmp_group->next) { + for (tmp_group = netif_igmp_data(netif); tmp_group != NULL; tmp_group = tmp_group->next) { if (tmp_group->next == group) { tmp_group->next = group->next; break;