zebra: Delay the usage of one variable until need

In the loop, local variable `ip` is always set even if the check condition
is not satisfied.

Avoid the redundant set, move this set exactly after the check condition is
satisfied. Set `ip` only if the check condition is met, otherwise needn't.

Signed-off-by: anlan_cs <vic.lan@pica8.com>
This commit is contained in:
anlan_cs 2022-02-06 23:47:49 -05:00
parent 2821405a69
commit 38eda16a24

View File

@ -344,10 +344,10 @@ int zebra_evpn_add_macip_for_intf(struct interface *ifp,
for (ALL_LIST_ELEMENTS(ifp->connected, cnode, cnnode, c)) { for (ALL_LIST_ELEMENTS(ifp->connected, cnode, cnnode, c)) {
struct ipaddr ip; struct ipaddr ip;
memset(&ip, 0, sizeof(struct ipaddr));
if (!CHECK_FLAG(c->conf, ZEBRA_IFC_REAL)) if (!CHECK_FLAG(c->conf, ZEBRA_IFC_REAL))
continue; continue;
memset(&ip, 0, sizeof(struct ipaddr));
if (c->address->family == AF_INET) { if (c->address->family == AF_INET) {
ip.ipa_type = IPADDR_V4; ip.ipa_type = IPADDR_V4;
memcpy(&(ip.ipaddr_v4), &(c->address->u.prefix4), memcpy(&(ip.ipaddr_v4), &(c->address->u.prefix4),