Mercurial > hg > nginx
comparison src/os/unix/ngx_channel.c @ 3396:2c5e269d0608
fix building by gcc 4.x with -O2/3/s in some Linux distributions:
dereferencing type-punned pointer will break strict-aliasing rules
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 22 Dec 2009 15:29:56 +0000 |
parents | d880fa02fb65 |
children | e76fbd1a49f3 |
comparison
equal
deleted
inserted
replaced
3395:4e15548b29d4 | 3396:2c5e269d0608 |
---|---|
34 msg.msg_controllen = sizeof(cmsg); | 34 msg.msg_controllen = sizeof(cmsg); |
35 | 35 |
36 cmsg.cm.cmsg_len = CMSG_LEN(sizeof(int)); | 36 cmsg.cm.cmsg_len = CMSG_LEN(sizeof(int)); |
37 cmsg.cm.cmsg_level = SOL_SOCKET; | 37 cmsg.cm.cmsg_level = SOL_SOCKET; |
38 cmsg.cm.cmsg_type = SCM_RIGHTS; | 38 cmsg.cm.cmsg_type = SCM_RIGHTS; |
39 *(int *) CMSG_DATA(&cmsg.cm) = ch->fd; | 39 |
40 /* | |
41 * We have to use ngx_memcpy() instead of simple | |
42 * *(int *) CMSG_DATA(&cmsg.cm) = ch->fd; | |
43 * because some gcc 4.4 with -O2/3/s optimization issues the warning: | |
44 * dereferencing type-punned pointer will break strict-aliasing rules | |
45 * | |
46 * Fortunately, gcc with -O1 compiles this ngx_memcpy() | |
47 * in the same simple assigment as in the code above | |
48 */ | |
49 | |
50 ngx_memcpy(CMSG_DATA(&cmsg.cm), &ch->fd, sizeof(int)); | |
40 } | 51 } |
41 | 52 |
42 msg.msg_flags = 0; | 53 msg.msg_flags = 0; |
43 | 54 |
44 #else | 55 #else |
151 "level %d or type %d", | 162 "level %d or type %d", |
152 cmsg.cm.cmsg_level, cmsg.cm.cmsg_type); | 163 cmsg.cm.cmsg_level, cmsg.cm.cmsg_type); |
153 return NGX_ERROR; | 164 return NGX_ERROR; |
154 } | 165 } |
155 | 166 |
156 ch->fd = *(int *) CMSG_DATA(&cmsg.cm); | 167 /* ch->fd = *(int *) CMSG_DATA(&cmsg.cm); */ |
168 | |
169 ngx_memcpy(&ch->fd, CMSG_DATA(&cmsg.cm), sizeof(int)); | |
157 } | 170 } |
158 | 171 |
159 if (msg.msg_flags & (MSG_TRUNC|MSG_CTRUNC)) { | 172 if (msg.msg_flags & (MSG_TRUNC|MSG_CTRUNC)) { |
160 ngx_log_error(NGX_LOG_ALERT, log, 0, | 173 ngx_log_error(NGX_LOG_ALERT, log, 0, |
161 "recvmsg() truncated data"); | 174 "recvmsg() truncated data"); |