aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2009-12-22 15:29:56 +0000
committerIgor Sysoev <igor@sysoev.ru>2009-12-22 15:29:56 +0000
commitfb0c73b08d869dfc396fd04b925512d3bda71a21 (patch)
tree4c4de9afd3e1b9cbfbf596bf8582e6dcbc1943cd /src
parent8c97fa9ae4941e11ed000e2fbcc4de66caa447a3 (diff)
downloadnginx-fb0c73b08d869dfc396fd04b925512d3bda71a21.tar.gz
nginx-fb0c73b08d869dfc396fd04b925512d3bda71a21.zip
fix building by gcc 4.x with -O2/3/s in some Linux distributions:
dereferencing type-punned pointer will break strict-aliasing rules
Diffstat (limited to 'src')
-rw-r--r--src/os/unix/ngx_channel.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/os/unix/ngx_channel.c b/src/os/unix/ngx_channel.c
index f0f337d06..a9ac45c9c 100644
--- a/src/os/unix/ngx_channel.c
+++ b/src/os/unix/ngx_channel.c
@@ -36,7 +36,18 @@ ngx_write_channel(ngx_socket_t s, ngx_channel_t *ch, size_t size,
cmsg.cm.cmsg_len = CMSG_LEN(sizeof(int));
cmsg.cm.cmsg_level = SOL_SOCKET;
cmsg.cm.cmsg_type = SCM_RIGHTS;
- *(int *) CMSG_DATA(&cmsg.cm) = ch->fd;
+
+ /*
+ * We have to use ngx_memcpy() instead of simple
+ * *(int *) CMSG_DATA(&cmsg.cm) = ch->fd;
+ * because some gcc 4.4 with -O2/3/s optimization issues the warning:
+ * dereferencing type-punned pointer will break strict-aliasing rules
+ *
+ * Fortunately, gcc with -O1 compiles this ngx_memcpy()
+ * in the same simple assigment as in the code above
+ */
+
+ ngx_memcpy(CMSG_DATA(&cmsg.cm), &ch->fd, sizeof(int));
}
msg.msg_flags = 0;
@@ -153,7 +164,9 @@ ngx_read_channel(ngx_socket_t s, ngx_channel_t *ch, size_t size, ngx_log_t *log)
return NGX_ERROR;
}
- ch->fd = *(int *) CMSG_DATA(&cmsg.cm);
+ /* ch->fd = *(int *) CMSG_DATA(&cmsg.cm); */
+
+ ngx_memcpy(&ch->fd, CMSG_DATA(&cmsg.cm), sizeof(int));
}
if (msg.msg_flags & (MSG_TRUNC|MSG_CTRUNC)) {