summaryrefslogtreecommitdiff
path: root/lib/nexthop_group.c
diff options
context:
space:
mode:
authorStephen Worley <sworley@cumulusnetworks.com>2019-09-03 16:43:42 -0400
committerStephen Worley <sworley@cumulusnetworks.com>2019-10-25 11:13:43 -0400
commitdd9546e1966e91de0f88bdcba19c93440b8df006 (patch)
treed04032ceb96c0e7e8419fad66c80def5a0afb1a0 /lib/nexthop_group.c
parentfec211ad95a3a2967e72d49ab3036ae01e4b3762 (diff)
lib: Add NULL check in nexthop_group_equal*() iter
Add NULL checks in `nexthop_group_equal*()` iteration before calling `nexthop_same()` to make Clang SA happy. Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
Diffstat (limited to 'lib/nexthop_group.c')
-rw-r--r--lib/nexthop_group.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/nexthop_group.c b/lib/nexthop_group.c
index 54868d7fca..35599488bf 100644
--- a/lib/nexthop_group.c
+++ b/lib/nexthop_group.c
@@ -145,12 +145,19 @@ bool nexthop_group_equal_no_recurse(const struct nexthop_group *nhg1,
if (!nhg1 && nhg2)
return false;
+ if (nhg1 == nhg2)
+ return true;
+
if (nexthop_group_nexthop_num_no_recurse(nhg1)
!= nexthop_group_nexthop_num_no_recurse(nhg2))
return false;
for (nh1 = nhg1->nexthop, nh2 = nhg2->nexthop; nh1 || nh2;
nh1 = nh1->next, nh2 = nh2->next) {
+ if (nh1 && !nh2)
+ return false;
+ if (!nh1 && nh2)
+ return false;
if (!nexthop_same(nh1, nh2))
return false;
}
@@ -171,11 +178,18 @@ bool nexthop_group_equal(const struct nexthop_group *nhg1,
if (!nhg1 && nhg2)
return false;
+ if (nhg1 == nhg2)
+ return true;
+
if (nexthop_group_nexthop_num(nhg1) != nexthop_group_nexthop_num(nhg2))
return false;
for (nh1 = nhg1->nexthop, nh2 = nhg2->nexthop; nh1 || nh2;
nh1 = nexthop_next(nh1), nh2 = nexthop_next(nh2)) {
+ if (nh1 && !nh2)
+ return false;
+ if (!nh1 && nh2)
+ return false;
if (!nexthop_same(nh1, nh2))
return false;
}