Merge pull request #9039 from ton31337/fix/no_need_to_check_for_null_in_cmp_functions

bgpd: Do not check for NULL values for vni_hash_cmp()
This commit is contained in:
Donald Sharp 2021-07-13 16:42:23 -04:00 committed by GitHub
commit 6e95e6419c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 5 deletions

View File

@ -111,11 +111,7 @@ static bool vni_hash_cmp(const void *p1, const void *p2)
const struct bgpevpn *vpn1 = p1;
const struct bgpevpn *vpn2 = p2;
if (!vpn1 && !vpn2)
return true;
if (!vpn1 || !vpn2)
return false;
return (vpn1->vni == vpn2->vni);
return vpn1->vni == vpn2->vni;
}
int vni_list_cmp(void *p1, void *p2)

View File

@ -0,0 +1,20 @@
// There is no need to test for null values in the hash compare
// function as that we are guaranteed to send in data in
// the hash compare functions.
@@
identifier fn =~ "_hash_cmp";
type T;
identifier p1;
identifier p2;
@@
?static
T fn(...)
{
...
- if (p1 == NULL && p2 == NULL)
- return ...;
- if (p1 == NULL || p2 == NULL)
- return ...;
...
}