From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=C/MLoQfO; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTP id B03695A0279 for ; Sun, 18 Aug 2024 17:45:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723995909; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6ahcmZh/EUeh+dNbcch3gZliKE6EQHRsNS6QcLmr9dw=; b=C/MLoQfOeuCX17lFvrsbAu6Qtyue/bvyso2aHsOXPyLpx02zimz5NgPKy9+/nTgYINx25b Eim/P3K1cXs4k0EmmQExbu/waFu1zYrFqd+jGj3muguZOcX9b97W/pxlED8T1BtKHLFVgd u3/D7kpZmYqFzf6OqmHxk6GEBC/YF1g= Received: from mail-oa1-f69.google.com (mail-oa1-f69.google.com [209.85.160.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-115-IsvpLfQjPNWy6Qpr4k7CIQ-1; Sun, 18 Aug 2024 11:45:08 -0400 X-MC-Unique: IsvpLfQjPNWy6Qpr4k7CIQ-1 Received: by mail-oa1-f69.google.com with SMTP id 586e51a60fabf-27047178e2fso1365467fac.0 for ; Sun, 18 Aug 2024 08:45:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723995907; x=1724600707; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=6ahcmZh/EUeh+dNbcch3gZliKE6EQHRsNS6QcLmr9dw=; b=tyyKOkys0s50zYJvIb2iTa+WqFtEaEqWorKsOfVA+OMLIlRuRzaCbgPFytC7kzbqZl JxcvOkg6jIpAAg5r5EwoMgljwG3TulFXTVYzkZkhdWEmP1o7NAhNoS7Ps06fV3QFcv01 WCQQ8kWlEpuh6WRc+PTEWAX8+HrbAQKzcN4qj38RavxOSDk736fz7/7HAgdxcR6IzThg la0dd485T3yqh+Mr2QUphJIv/Dc3oDSsX2oHaqPIRWrJ5p5y2W9rxiMVQDpgFapVBK2Q Sj3+NFQsos+2GlznVt1zNx0ogKe7divdXJkSwpYxHMKejujIeEJiq9ZqwRjUx7iBpMgZ ImOA== X-Gm-Message-State: AOJu0YxyI8ot3Yg+nG0YbS9WF1lOHDC9pXJ0UoCnvqr3320WvWVbYk9e jl8Ly8+cBdNrcmqmzEUmNU4xTTRzgSN3Iv0iAaBOKqMBzh3pRLb9pLM/Wm7Xd6/4vn2vwU2DSsR GF11oYh2YgLH0kYCopXAjs8jBK5k4+hiquL4J6NlxQqq/9mgrqw== X-Received: by 2002:a05:6870:9a12:b0:260:e4ac:72e5 with SMTP id 586e51a60fabf-2701c3fc8a0mr10659876fac.25.1723995907295; Sun, 18 Aug 2024 08:45:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IExhKH+HXxNUZiZZFeXXc5jer4OBdaBOkkHDITwjYLm4NbkL2IRs7RstWId9znRXKkGN3qdyg== X-Received: by 2002:a05:6870:9a12:b0:260:e4ac:72e5 with SMTP id 586e51a60fabf-2701c3fc8a0mr10659865fac.25.1723995907008; Sun, 18 Aug 2024 08:45:07 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7127af3fdfcsm5336882b3a.219.2024.08.18.08.45.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Aug 2024 08:45:06 -0700 (PDT) Date: Sun, 18 Aug 2024 17:45:03 +0200 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 04/22] treewide: Use struct assignment instead of memcpy() for IP addresses Message-ID: <20240818174503.2530d030@elisabeth> In-Reply-To: <20240816054004.1335006-5-david@gibson.dropbear.id.au> References: <20240816054004.1335006-1-david@gibson.dropbear.id.au> <20240816054004.1335006-5-david@gibson.dropbear.id.au> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: ENDJFSQTCHPM5ZEZ5BWVUWLS3FSCKEVZ X-Message-ID-Hash: ENDJFSQTCHPM5ZEZ5BWVUWLS3FSCKEVZ X-MailFrom: sbrivio@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top, Paul Holzinger X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Fri, 16 Aug 2024 15:39:45 +1000 David Gibson wrote: > We rely on C11 already, so we can use clearer and more type-checkable > struct assignment instead of mempcy() for copying IP addresses around. > > This exposes some "pointer could be const" warnings from cppcheck, so > address those too. > > Signed-off-by: David Gibson > --- > conf.c | 12 ++++++------ > dhcpv6.c | 10 ++++++---- > 2 files changed, 12 insertions(+), 10 deletions(-) > > diff --git a/conf.c b/conf.c > index 750fdc86..9b05afeb 100644 > --- a/conf.c > +++ b/conf.c > @@ -389,14 +389,14 @@ static void add_dns6(struct ctx *c, > /* Guest or container can only access local addresses via redirect */ > if (IN6_IS_ADDR_LOOPBACK(addr)) { > if (!c->no_map_gw) { > - memcpy(*conf, &c->ip6.gw, sizeof(**conf)); > + **conf = c->ip6.gw; > (*conf)++; > > if (IN6_IS_ADDR_UNSPECIFIED(&c->ip6.dns_match)) > - memcpy(&c->ip6.dns_match, addr, sizeof(*addr)); > + c->ip6.dns_match = *addr; > } > } else { > - memcpy(*conf, addr, sizeof(**conf)); > + **conf = *addr; > (*conf)++; > } > > @@ -632,7 +632,7 @@ static unsigned int conf_ip4(unsigned int ifi, > ip4->prefix_len = 32; > } > > - memcpy(&ip4->addr_seen, &ip4->addr, sizeof(ip4->addr_seen)); > + ip4->addr_seen = ip4->addr; > > if (MAC_IS_ZERO(mac)) { > int rc = nl_link_get_mac(nl_sock, ifi, mac); > @@ -693,8 +693,8 @@ static unsigned int conf_ip6(unsigned int ifi, > return 0; > } > > - memcpy(&ip6->addr_seen, &ip6->addr, sizeof(ip6->addr)); > - memcpy(&ip6->addr_ll_seen, &ip6->addr_ll, sizeof(ip6->addr_ll)); > + ip6->addr_seen = ip6->addr; > + ip6->addr_ll_seen = ip6->addr_ll; > > if (MAC_IS_ZERO(mac)) { > rc = nl_link_get_mac(nl_sock, ifi, mac); > diff --git a/dhcpv6.c b/dhcpv6.c > index bbed41dc..87b3c3eb 100644 > --- a/dhcpv6.c > +++ b/dhcpv6.c > @@ -298,7 +298,8 @@ static struct opt_hdr *dhcpv6_ia_notonlink(const struct pool *p, > { > char buf[INET6_ADDRSTRLEN]; > struct in6_addr req_addr; > - struct opt_hdr *ia, *h; > + const struct opt_hdr *h; > + struct opt_hdr *ia; > size_t offset; > int ia_type; > > @@ -312,12 +313,13 @@ ia_ta: > offset += sizeof(struct opt_ia_na); > > while ((h = dhcpv6_opt(p, &offset, OPT_IAAADR))) { > - struct opt_ia_addr *opt_addr = (struct opt_ia_addr *)h; > + const struct opt_ia_addr *opt_addr > + = (const struct opt_ia_addr *)h; Nit: the assignment could go on its own line, then? > if (ntohs(h->l) != OPT_VSIZE(ia_addr)) > return NULL; > > - memcpy(&req_addr, &opt_addr->addr, sizeof(req_addr)); > + req_addr = opt_addr->addr; > if (!IN6_ARE_ADDR_EQUAL(la, &req_addr)) { > info("DHCPv6: requested address %s not on link", > inet_ntop(AF_INET6, &req_addr, > @@ -363,7 +365,7 @@ static size_t dhcpv6_dns_fill(const struct ctx *c, char *buf, int offset) > srv->hdr.l = 0; > } > > - memcpy(&srv->addr[i], &c->ip6.dns[i], sizeof(srv->addr[i])); > + srv->addr[i] = c->ip6.dns[i]; > srv->hdr.l += sizeof(srv->addr[i]); > offset += sizeof(srv->addr[i]); > } I only reviewed up to this patch so far. -- Stefano