[LEDE-DEV] [PATCH] umdns: Replace unnecessary memset calls with {}.
Zefir Kurtisi
zefir.kurtisi at neratec.com
Wed Nov 8 01:57:57 PST 2017
On 11/07/2017 09:24 PM, Rosen Penev wrote:
> Less verbose
>
> Signed-off-by: Rosen Penev <rosenp at gmail.com>
> ---
> 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));
> cmsg = CMSG_FIRSTHDR(&m);
> cmsg->cmsg_len = m.msg_controllen;
> cmsg->cmsg_level = IPPROTO_IP;
This one looks like a pitfall to me, since without the memset cmsg_data being
static is never zeroed again at runtime. Not sure if all cmsg members are
initialized after the removed memset, otherwise the change is wrong.
Cheers,
Zefir
More information about the Lede-dev
mailing list