summaryrefslogtreecommitdiffstats
path: root/serprog.c
diff options
context:
space:
mode:
authorCarl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>2009-09-05 01:10:23 +0000
committerCarl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>2009-09-05 01:10:23 +0000
commit6d1256082c4c11f556c278b907c19ac89ba51ca4 (patch)
tree56c158a7149518df27a85d36b36ca41a66e44ef1 /serprog.c
parent95e892b9d35c82ad372af4e9fab22f1c395ebc2d (diff)
downloadast2050-flashrom-6d1256082c4c11f556c278b907c19ac89ba51ca4.zip
ast2050-flashrom-6d1256082c4c11f556c278b907c19ac89ba51ca4.tar.gz
Fix strict aliasing in serprog
Initialize the sockaddr,sockaddr_in union directly instead of running memset later. Corresponding to flashrom svn r715. Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Acked-by: Stefan Reinauer <stepan@coresystems.de>
Diffstat (limited to 'serprog.c')
-rw-r--r--serprog.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/serprog.c b/serprog.c
index 23e1a0c..ee72da3 100644
--- a/serprog.c
+++ b/serprog.c
@@ -105,7 +105,7 @@ static int sp_opensocket(char *ip, unsigned int port)
{
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 @@ static int sp_opensocket(char *ip, unsigned int port)
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");
}
OpenPOWER on IntegriCloud