public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Fix initializing a static union variable
@ 2024-06-20 18:17 Yabin Cui
  2024-06-20 19:31 ` Nick Desaulniers
  2024-06-21 11:01 ` Przemek Kitszel
  0 siblings, 2 replies; 11+ messages in thread
From: Yabin Cui @ 2024-06-20 18:17 UTC (permalink / raw)
  To: Steffen Klassert, Herbert Xu, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Nathan Chancellor, Nick Desaulniers,
	Bill Wendling, Justin Stitt
  Cc: netdev, linux-kernel, llvm, Yabin Cui

saddr_wildcard is a static union variable initialized with {}.
But c11 standard doesn't guarantee initializing all fields as
zero for this case. As in https://godbolt.org/z/rWvdv6aEx,
clang only initializes the first field as zero, but the bits
corresponding to other (larger) members are undefined.

Signed-off-by: Yabin Cui <yabinc@google.com>
---
 net/xfrm/xfrm_state.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
index 649bb739df0d..9bc69d703e5c 100644
--- a/net/xfrm/xfrm_state.c
+++ b/net/xfrm/xfrm_state.c
@@ -1139,7 +1139,7 @@ xfrm_state_find(const xfrm_address_t *daddr, const xfrm_address_t *saddr,
 		struct xfrm_policy *pol, int *err,
 		unsigned short family, u32 if_id)
 {
-	static xfrm_address_t saddr_wildcard = { };
+	static const xfrm_address_t saddr_wildcard;
 	struct net *net = xp_net(pol);
 	unsigned int h, h_wildcard;
 	struct xfrm_state *x, *x0, *to_put;
-- 
2.45.2.741.gdbec12cfda-goog


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2024-06-24 18:05 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-20 18:17 [PATCH] Fix initializing a static union variable Yabin Cui
2024-06-20 19:31 ` Nick Desaulniers
2024-06-20 19:47   ` Nick Desaulniers
2024-06-20 19:54     ` Nick Desaulniers
2024-06-21 11:24       ` Ballman, Aaron
2024-06-21 20:49         ` Yabin Cui
2024-06-21 11:07   ` Herbert Xu
2024-06-23 16:51     ` Linus Torvalds
2024-06-23 17:05       ` Linus Torvalds
2024-06-24 18:04         ` Yabin Cui
2024-06-21 11:01 ` Przemek Kitszel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox