From ed409ccd3ef8778e3041fd5fe27b9324be15f47b Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Sat, 23 Nov 2013 10:16:38 +0100 Subject: [PATCH] clang: use ETHER_ADDR_LEN instead of sizeof() This allows clang to not choke on inappropriate types. --- src/daemon/cdp.c | 2 +- src/daemon/edp.c | 2 +- src/daemon/interfaces.c | 13 ++++++------- src/daemon/lldp.c | 2 +- src/daemon/sonmp.c | 2 +- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/daemon/cdp.c b/src/daemon/cdp.c index bf5921d9..3ddbdffb 100644 --- a/src/daemon/cdp.c +++ b/src/daemon/cdp.c @@ -67,7 +67,7 @@ cdp_send(struct lldpd *global, /* Ethernet header */ if (!( POKE_BYTES(mcastaddr, sizeof(mcastaddr)) && - POKE_BYTES(&hardware->h_lladdr, sizeof(hardware->h_lladdr)) && + POKE_BYTES(&hardware->h_lladdr, ETHER_ADDR_LEN) && POKE_SAVE(pos_len_eh) && /* We compute the len later */ POKE_UINT16(0))) goto toobig; diff --git a/src/daemon/edp.c b/src/daemon/edp.c index 4a9cfbdc..106d9f63 100644 --- a/src/daemon/edp.c +++ b/src/daemon/edp.c @@ -64,7 +64,7 @@ edp_send(struct lldpd *global, /* Ethernet header */ if (!( POKE_BYTES(mcastaddr, sizeof(mcastaddr)) && - POKE_BYTES(&hardware->h_lladdr, sizeof(hardware->h_lladdr)) && + POKE_BYTES(&hardware->h_lladdr, ETHER_ADDR_LEN) && POKE_SAVE(pos_len_eh) && /* We compute the len later */ POKE_UINT16(0))) goto toobig; diff --git a/src/daemon/interfaces.c b/src/daemon/interfaces.c index 2af06331..1a39e18d 100644 --- a/src/daemon/interfaces.c +++ b/src/daemon/interfaces.c @@ -344,15 +344,15 @@ interfaces_helper_chassis(struct lldpd *cfg, /* That's odd. Let's skip. */ continue; - name = malloc(sizeof(hardware->h_lladdr)); + name = malloc(ETHER_ADDR_LEN); if (!name) { log_warn("interfaces", "not enough memory for chassis ID"); return; } free(LOCAL_CHASSIS(cfg)->c_id); - memcpy(name, hardware->h_lladdr, sizeof(hardware->h_lladdr)); + memcpy(name, hardware->h_lladdr, ETHER_ADDR_LEN); LOCAL_CHASSIS(cfg)->c_id = name; - LOCAL_CHASSIS(cfg)->c_id_len = sizeof(hardware->h_lladdr); + LOCAL_CHASSIS(cfg)->c_id_len = ETHER_ADDR_LEN; LOCAL_CHASSIS(cfg)->c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR; return; } @@ -476,11 +476,10 @@ interfaces_helper_port_name_desc(struct lldpd_hardware *hardware, hardware->h_ifname); port->p_id_subtype = LLDP_PORTID_SUBTYPE_LLADDR; if ((port->p_id = - calloc(1, sizeof(hardware->h_lladdr))) == NULL) + calloc(1, ETHER_ADDR_LEN)) == NULL) fatal("interfaces", NULL); - memcpy(port->p_id, hardware->h_lladdr, - sizeof(hardware->h_lladdr)); - port->p_id_len = sizeof(hardware->h_lladdr); + memcpy(port->p_id, hardware->h_lladdr, ETHER_ADDR_LEN); + port->p_id_len = ETHER_ADDR_LEN; port->p_descr = strdup(hardware->h_ifname); return; } diff --git a/src/daemon/lldp.c b/src/daemon/lldp.c index 65843090..38403aa9 100644 --- a/src/daemon/lldp.c +++ b/src/daemon/lldp.c @@ -94,7 +94,7 @@ lldp_send(struct lldpd *global, /* LLDP multicast address */ POKE_BYTES(mcastaddr, sizeof(mcastaddr)) && /* Source MAC address */ - POKE_BYTES(&hardware->h_lladdr, sizeof(hardware->h_lladdr)) && + POKE_BYTES(&hardware->h_lladdr, ETHER_ADDR_LEN) && /* LLDP frame */ POKE_UINT16(ETHERTYPE_LLDP))) goto toobig; diff --git a/src/daemon/sonmp.c b/src/daemon/sonmp.c index 75638d1c..30930cb3 100644 --- a/src/daemon/sonmp.c +++ b/src/daemon/sonmp.c @@ -207,7 +207,7 @@ sonmp_send(struct lldpd *global, /* SONMP multicast address as target */ POKE_BYTES(mcastaddr, sizeof(mcastaddr)) && /* Source MAC addresss */ - POKE_BYTES(&hardware->h_lladdr, sizeof(hardware->h_lladdr)) && + POKE_BYTES(&hardware->h_lladdr, ETHER_ADDR_LEN) && /* SONMP frame is of fixed size */ POKE_UINT16(SONMP_SIZE))) goto toobig; -- 2.39.5