From: Andreas Schwab Date: Mon, 19 Sep 2022 08:10:09 +0000 (+0200) Subject: socket: Use offsetof in SUN_LEN (bug 29578) X-Git-Tag: upstream/2.37~265 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c15318bfc5499d835c434a4d98b688aa2d928412;p=platform%2Fupstream%2Fglibc.git socket: Use offsetof in SUN_LEN (bug 29578) Use offsetof instead of its traditional expansion in the definition of the SUN_LEN macro, to avoid a warning from the undefined behaviour sanitizer. --- diff --git a/socket/sys/un.h b/socket/sys/un.h index 454eafe..2b11300 100644 --- a/socket/sys/un.h +++ b/socket/sys/un.h @@ -34,10 +34,11 @@ struct sockaddr_un #ifdef __USE_MISC +# include # include /* 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