[LEDE-DEV] [PATCH] umdns: Replace unnecessary memset calls with {}.

Rosen Penev rosenp at gmail.com
Wed Nov 8 10:57:43 PST 2017


Less verbose.

Signed-off-by: Rosen Penev <rosenp at gmail.com>

v2: some of those memset calls are needed. Also replace { 0 } with {}.
---
 interface.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/interface.c b/interface.c
index 7f814d2..deabcbb 100644
--- a/interface.c
+++ b/interface.c
@@ -186,7 +186,7 @@ read_socket4(struct uloop_fd *u, unsigned int events)
 	struct iovec iov[1];
 	char cmsg[CMSG_SPACE(sizeof(struct in_pktinfo)) + CMSG_SPACE(sizeof(int)) + 1];
 	struct cmsghdr *cmsgptr;
-	struct msghdr msg;
+	struct msghdr msg = {};
 	socklen_t len;
 	struct sockaddr_in from;
 	int flags = 0, ifindex = -1;
@@ -202,7 +202,6 @@ read_socket4(struct uloop_fd *u, unsigned int events)
 	iov[0].iov_base = buffer;
 	iov[0].iov_len = sizeof(buffer);
 
-	memset(&msg, 0, sizeof(msg));
 	msg.msg_name = (struct sockaddr *) &from;
 	msg.msg_namelen = sizeof(struct sockaddr_in);
 	msg.msg_iov = iov;
@@ -260,7 +259,7 @@ read_socket6(struct uloop_fd *u, unsigned int events)
 	struct iovec iov[1];
 	char cmsg6[CMSG_SPACE(sizeof(struct in6_pktinfo)) + CMSG_SPACE(sizeof(int)) + 1];
 	struct cmsghdr *cmsgptr;
-	struct msghdr msg;
+	struct msghdr msg = {};
 	socklen_t len;
 	struct sockaddr_in6 from;
 	int flags = 0, ifindex = -1;
@@ -276,7 +275,6 @@ read_socket6(struct uloop_fd *u, unsigned int events)
 	iov[0].iov_base = buffer;
 	iov[0].iov_len = sizeof(buffer);
 
-	memset(&msg, 0, sizeof(msg));
 	msg.msg_name = (struct sockaddr *) &from;
 	msg.msg_namelen = sizeof(struct sockaddr_in6);
 	msg.msg_iov = iov;
@@ -327,17 +325,16 @@ read_socket6(struct uloop_fd *u, unsigned int events)
 static int
 interface_mcast_setup4(struct interface *iface)
 {
-	struct ip_mreqn mreq;
+	struct ip_mreqn mreq = {};
 	uint8_t ttl = 255;
 	int no = 0;
-	struct sockaddr_in sa = { 0 };
+	struct sockaddr_in sa = {};
 	int fd = iface->fd.fd;
 
 	sa.sin_family = AF_INET;
 	sa.sin_port = htons(MCAST_PORT);
 	inet_pton(AF_INET, MCAST_ADDR, &sa.sin_addr);
 
-	memset(&mreq, 0, sizeof(mreq));
 	mreq.imr_address.s_addr = iface->v4_addr.s_addr;
 	mreq.imr_multiaddr = sa.sin_addr;
 	mreq.imr_ifindex = iface->ifindex;
@@ -368,17 +365,16 @@ interface_mcast_setup4(struct interface *iface)
 static int
 interface_socket_setup6(struct interface *iface)
 {
-	struct ipv6_mreq mreq;
+	struct ipv6_mreq mreq = {};
 	int ttl = 255;
 	int no = 0;
-	struct sockaddr_in6 sa = { 0 };
+	struct sockaddr_in6 sa = {};
 	int fd = iface->fd.fd;
 
 	sa.sin6_family = AF_INET6;
 	sa.sin6_port = htons(MCAST_PORT);
 	inet_pton(AF_INET6, MCAST_ADDR6, &sa.sin6_addr);
 
-	memset(&mreq, 0, sizeof(mreq));
 	mreq.ipv6mr_multiaddr = sa.sin6_addr;
 	mreq.ipv6mr_interface = iface->ifindex;
 
-- 
2.13.6




More information about the Lede-dev mailing list