This is the mail archive of the glibc-cvs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[glibc/zack/no-nested-includes] sys/un.h: Don’t include string.h for strlen.


https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=7601868f254a09a17045ec4d6a0fceeceb99aea8

commit 7601868f254a09a17045ec4d6a0fceeceb99aea8
Author: Zack Weinberg <zackw@panix.com>
Date:   Wed May 22 12:03:57 2019 -0400

    sys/un.h: Donâ??t include string.h for strlen.
    
    sys/un.h needs strlen in order to define SUN_LEN, but does not need
    any of the other things declared by string.h; the path of least
    resistance is to prototype strlen locally.
    
    Also, the construct being used to get the size of everything up to the
    sun_path member contains a formal dereference of a null pointer and
    therefore has undefined behavior.  Replace with __SOCKADDR_COMMON_SIZE.
    
    	* sys/un.h [__USE_MISC]: Donâ??t include string.h.  Prototype
    	strlen locally.  Use __SOCKADDR_COMMON_SIZE for size of
    	leading members of struct sockaddr_un.
    	* scripts/check-obsolete-constructs.py (HEADER_ALLOWED_INCLUDES): Update.

Diff:
---
 scripts/check-obsolete-constructs.py | 1 -
 socket/sys/un.h                      | 6 +++---
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/scripts/check-obsolete-constructs.py b/scripts/check-obsolete-constructs.py
index 6eb366e..e545bfa 100755
--- a/scripts/check-obsolete-constructs.py
+++ b/scripts/check-obsolete-constructs.py
@@ -543,7 +543,6 @@ HEADER_ALLOWED_INCLUDES = {
     "sys/shm.h":                   [ "sys/ipc.h" ],
     "sys/time.h":                  [ "sys/select.h" ],
     "sys/types.h":                 [ "endian.h" ],
-    "sys/un.h":                    [ "string.h" ],
     "sys/wait.h":                  [ "signal.h" ],
 
     # POSIX networking headers
diff --git a/socket/sys/un.h b/socket/sys/un.h
index 8c7433a..8097436 100644
--- a/socket/sys/un.h
+++ b/socket/sys/un.h
@@ -34,11 +34,11 @@ struct sockaddr_un
 
 
 #ifdef __USE_MISC
-# include <string.h>		/* For prototype of `strlen'.  */
+extern size_t strlen (const char *__s)
+     __THROW __attribute_pure__ __nonnull ((1));
 
 /* Evaluate to actual length of the `sockaddr_un' structure.  */
-# define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path)	      \
-		      + strlen ((ptr)->sun_path))
+# define SUN_LEN(ptr) (__SOCKADDR_COMMON_SIZE + strlen ((ptr)->sun_path))
 #endif
 
 __END_DECLS


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]