[LEDE-DEV] [PATCH] umdns: Replace unnecessary memset calls with {}.
Jo-Philipp Wich
jo at mein.io
Wed Nov 8 02:14:02 PST 2017
Hi,
comments inline.
> ---
> interface.c | 22 ++++++++--------------
> 1 file changed, 8 insertions(+), 14 deletions(-)
>
> diff --git a/interface.c b/interface.c
> index 7f814d2..18dee52 100644
> --- a/interface.c
> +++ b/interface.c
> @@ -44,7 +44,7 @@
> static int
> interface_send_packet4(struct interface *iface, struct sockaddr_in *to, struct iovec *iov, int iov_len)
> {
> - static size_t cmsg_data[( CMSG_SPACE(sizeof(struct in_pktinfo)) / sizeof(size_t)) + 1];
> + static size_t cmsg_data[( CMSG_SPACE(sizeof(struct in_pktinfo)) / sizeof(size_t)) + 1] = {};
> static struct sockaddr_in a;
> static struct msghdr m = {
> .msg_name = (struct sockaddr *) &a,
> @@ -61,7 +61,6 @@ interface_send_packet4(struct interface *iface, struct sockaddr_in *to, struct i
> m.msg_iov = iov;
> m.msg_iovlen = iov_len;
>
> - memset(cmsg_data, 0, sizeof(cmsg_data));
The cmsg_data buffer is static, wouldn't that mean that it is never
zeroed again after the first function call?
> cmsg = CMSG_FIRSTHDR(&m);
> cmsg->cmsg_len = m.msg_controllen;
> cmsg->cmsg_level = IPPROTO_IP;
> @@ -84,7 +83,7 @@ interface_send_packet4(struct interface *iface, struct sockaddr_in *to, struct i
> static int
> interface_send_packet6(struct interface *iface, struct sockaddr_in6 *to, struct iovec *iov, int iov_len)
> {
> - static size_t cmsg_data[( CMSG_SPACE(sizeof(struct in6_pktinfo)) / sizeof(size_t)) + 1];
> + static size_t cmsg_data[( CMSG_SPACE(sizeof(struct in6_pktinfo)) / sizeof(size_t)) + 1] = {};
> static struct sockaddr_in6 a;
> static struct msghdr m = {
> .msg_name = (struct sockaddr *) &a,
> @@ -101,7 +100,6 @@ interface_send_packet6(struct interface *iface, struct sockaddr_in6 *to, struct
> m.msg_iov = iov;
> m.msg_iovlen = iov_len;
>
> - memset(cmsg_data, 0, sizeof(cmsg_data));
Same here, I think the buffer needs to be zeroed on each invocation.
> cmsg = CMSG_FIRSTHDR(&m);
> cmsg->cmsg_len = m.msg_controllen;
> cmsg->cmsg_level = IPPROTO_IPV6;
> @@ -186,7 +184,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;
[snip]
~ Jo
More information about the Lede-dev
mailing list