diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2017-05-17 13:35:52 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2017-05-17 13:36:56 -0700 |
commit | e54a3b4fde0c3de7964a2e604c7381101e5d9951 (patch) | |
tree | d663011b3e5c07c978078a4879f77907d1db3262 /src/conf_post.h | |
parent | 184d74ce002ecb7399cb2b47fc671bfb2feb9855 (diff) | |
download | emacs-e54a3b4fde0c3de7964a2e604c7381101e5d9951.tar.gz |
Avoid undefined behavior in struct sockaddr
Problem noted by Philipp Stephani in:
http://lists.gnu.org/archive/html/emacs-devel/2017-05/msg00391.html
* src/conf_post.h (ATTRIBUTE_MAY_ALIAS, DECLARE_POINTER_ALIAS):
New macros.
* src/process.c (conv_sockaddr_to_lisp, conv_lisp_to_sockaddr)
(connect_network_socket, network_interface_info)
(server_accept_connection): Use it when aliasing non-char objects.
Diffstat (limited to 'src/conf_post.h')
-rw-r--r-- | src/conf_post.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/conf_post.h b/src/conf_post.h index 1462bd16c75..c05c93b8190 100644 --- a/src/conf_post.h +++ b/src/conf_post.h @@ -263,6 +263,20 @@ extern int emacs_setenv_TZ (char const *); #define ATTRIBUTE_CONST _GL_ATTRIBUTE_CONST #define ATTRIBUTE_UNUSED _GL_UNUSED +#if GNUC_PREREQ (3, 3, 0) +# define ATTRIBUTE_MAY_ALIAS __attribute__ ((__may_alias__)) +#else +# define ATTRIBUTE_MAY_ALIAS +#endif + +/* Declare NAME to be a pointer to an object of type TYPE, initialized + to the address ADDR, which may be of a different type. Accesses + via NAME may alias with other accesses with the traditional + behavior, even if options like gcc -fstrict-aliasing are used. */ + +#define DECLARE_POINTER_ALIAS(name, type, addr) \ + type ATTRIBUTE_MAY_ALIAS *name = (type *) (addr) + #if 3 <= __GNUC__ # define ATTRIBUTE_MALLOC __attribute__ ((__malloc__)) #else |