This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [pushed] Fix struct sockaddr/sockaddr_in/sockaddr_un strict aliasing violations
- From: Eli Zaretskii <eliz at gnu dot org>
- To: Pedro Alves <palves at redhat dot com>
- Cc: gdb-patches at sourceware dot org
- Date: Sat, 07 Mar 2015 20:00:42 +0200
- Subject: Re: [pushed] Fix struct sockaddr/sockaddr_in/sockaddr_un strict aliasing violations
- Authentication-results: sourceware.org; auth=none
- References: <1425750266-14385-1-git-send-email-palves at redhat dot com>
- Reply-to: Eli Zaretskii <eliz at gnu dot org>
> From: Pedro Alves <palves@redhat.com>
> Date: Sat, 7 Mar 2015 17:44:26 +0000
>
> Building gdbserver in C++ mode shows:
>
> gdb/gdbserver/tracepoint.c: In function âvoid* gdb_agent_helper_thread(void*)â:
> gdb/gdbserver/tracepoint.c:7190:47: error: cannot convert âsockaddr_un*â to âsockaddr*â for argument â2â to âint accept(int, sockaddr*, socklen_t*)â
> fd = accept (listen_fd, &sockaddr, &tmp);
>
> A few places in the tree already have an explicit cast to struct
> sockaddr *, but that's a strict aliasing violation. Instead of
> propagating invalid code, fix this by using a union instead.
Yuck! Isn't there a better way? Why do we have the original problem
to begin with, i.e. where did the incompatible data type come from?
(Does it even make sense to work around C++ restrictions while
converting code to C++?)
Thanks.