Fix strict aliasing in serprog. Initialize the sockaddr,sockaddr_in union directly instead of running memset later.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Index: flashrom-strict_aliasing/serprog.c =================================================================== --- flashrom-strict_aliasing/serprog.c (revision 714) +++ flashrom-strict_aliasing/serprog.c (working copy) @@ -105,7 +105,7 @@ { int flag = 1; struct hostent *hostPtr = NULL; - struct sockaddr_in sp; + union { struct sockaddr_in si; struct sockaddr s; } sp = {}; int sock; printf_debug(MSGHEADER "IP %s port %d\n", ip, port); sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); @@ -117,11 +117,10 @@ if (NULL == hostPtr) sp_die("Error: cannot resolve"); } - memset(&sp, 0, sizeof(sp)); - sp.sin_family = AF_INET; - sp.sin_port = htons(port); - (void)memcpy(&sp.sin_addr, hostPtr->h_addr, hostPtr->h_length); - if (connect(sock, (struct sockaddr *)&sp, sizeof(sp)) < 0) { + sp.si.sin_family = AF_INET; + sp.si.sin_port = htons(port); + (void)memcpy(&sp.si.sin_addr, hostPtr->h_addr, hostPtr->h_length); + if (connect(sock, &sp.s, sizeof(sp.si)) < 0) { close(sock); sp_die("Error: serprog cannot connect"); }
On 04.09.2009 16:47, Carl-Daniel Hailfinger wrote:
Fix strict aliasing in serprog. Initialize the sockaddr,sockaddr_in union directly instead of running memset later.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Acked-by: Stefan Reinauer stepan@coresystems.de
Thanks, committed in r715.
Regards, Carl-Daniel