public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] socket: Use offsetof in SUN_LEN (bug 29578)
@ 2022-09-19 13:39 Andreas Schwab
  2022-10-06 17:36 ` Adhemerval Zanella Netto
  0 siblings, 1 reply; 2+ messages in thread
From: Andreas Schwab @ 2022-09-19 13:39 UTC (permalink / raw)
  To: libc-alpha

Use offsetof instead of its traditional expansion in the definition of the
SUN_LEN macro, to avoid a warning from the undefined behaviour sanitizer.
---
 socket/sys/un.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/socket/sys/un.h b/socket/sys/un.h
index 454eafebc9..2b11300e28 100644
--- a/socket/sys/un.h
+++ b/socket/sys/un.h
@@ -34,10 +34,11 @@ struct sockaddr_un
 
 
 #ifdef __USE_MISC
+# include <stddef.h>
 # include <string.h>		/* For prototype of `strlen'.  */
 
 /* Evaluate to actual length of the `sockaddr_un' structure.  */
-# define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path)	      \
+# define SUN_LEN(ptr) (offsetof (struct sockaddr_un, sun_path)		      \
 		      + strlen ((ptr)->sun_path))
 #endif
 
-- 
2.37.3


-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

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

* Re: [PATCH] socket: Use offsetof in SUN_LEN (bug 29578)
  2022-09-19 13:39 [PATCH] socket: Use offsetof in SUN_LEN (bug 29578) Andreas Schwab
@ 2022-10-06 17:36 ` Adhemerval Zanella Netto
  0 siblings, 0 replies; 2+ messages in thread
From: Adhemerval Zanella Netto @ 2022-10-06 17:36 UTC (permalink / raw)
  To: Andreas Schwab, libc-alpha



On 19/09/22 10:39, Andreas Schwab via Libc-alpha wrote:
> Use offsetof instead of its traditional expansion in the definition of the
> SUN_LEN macro, to avoid a warning from the undefined behaviour sanitizer.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> ---
>  socket/sys/un.h | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/socket/sys/un.h b/socket/sys/un.h
> index 454eafebc9..2b11300e28 100644
> --- a/socket/sys/un.h
> +++ b/socket/sys/un.h
> @@ -34,10 +34,11 @@ struct sockaddr_un
>  
>  
>  #ifdef __USE_MISC
> +# include <stddef.h>
>  # include <string.h>		/* For prototype of `strlen'.  */
>  
>  /* Evaluate to actual length of the `sockaddr_un' structure.  */
> -# define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path)	      \
> +# define SUN_LEN(ptr) (offsetof (struct sockaddr_un, sun_path)		      \
>  		      + strlen ((ptr)->sun_path))
>  #endif
>  

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

end of thread, other threads:[~2022-10-06 17:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-19 13:39 [PATCH] socket: Use offsetof in SUN_LEN (bug 29578) Andreas Schwab
2022-10-06 17:36 ` Adhemerval Zanella Netto

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).