diff options
author | Igor Sysoev <igor@sysoev.ru> | 2009-12-22 18:15:45 +0300 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2009-12-22 18:15:45 +0300 |
commit | 8c97fa9ae4941e11ed000e2fbcc4de66caa447a3 (patch) | |
tree | 36899801203d14b427d2d2832f0af3141ff9a8ce /src | |
parent | 9cf418ea92d4e65e564b30704f14342881a5b18a (diff) |
fix building by gcc 4.4 with -O2/3/s:
dereferencing pointer 'sin' does break strict-aliasing rules
Diffstat (limited to 'src')
-rw-r--r-- | src/http/ngx_http.c | 18 | ||||
-rw-r--r-- | src/http/ngx_http_core_module.c | 10 | ||||
-rw-r--r-- | src/http/ngx_http_core_module.h | 13 |
3 files changed, 26 insertions, 15 deletions
diff --git a/src/http/ngx_http.c b/src/http/ngx_http.c index 0a91d674f..4c856840b 100644 --- a/src/http/ngx_http.c +++ b/src/http/ngx_http.c @@ -1117,13 +1117,13 @@ ngx_http_add_listen(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf, } } - sa = (struct sockaddr *) &lsopt->sockaddr; + sa = &lsopt->u.sockaddr; switch (sa->sa_family) { #if (NGX_HAVE_INET6) case AF_INET6: - sin6 = (struct sockaddr_in6 *) sa; + sin6 = &lsopt->u.sockaddr_in6; p = sin6->sin6_port; break; #endif @@ -1135,7 +1135,7 @@ ngx_http_add_listen(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf, #endif default: /* AF_INET */ - sin = (struct sockaddr_in *) sa; + sin = &lsopt->u.sockaddr_in; p = sin->sin_port; break; } @@ -1185,7 +1185,7 @@ ngx_http_add_addresses(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf, * may fill some fields in inherited sockaddr struct's */ - sa = (struct sockaddr *) &lsopt->sockaddr; + sa = &lsopt->u.sockaddr; switch (sa->sa_family) { @@ -1209,13 +1209,13 @@ ngx_http_add_addresses(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf, break; } - p = lsopt->sockaddr + off; + p = lsopt->u.sockaddr_data + off; addr = port->addrs.elts; for (i = 0; i < port->addrs.nelts; i++) { - if (ngx_memcmp(p, (u_char *) addr[i].opt.sockaddr + off, len) != 0) { + if (ngx_memcmp(p, addr[i].opt.u.sockaddr_data + off, len) != 0) { continue; } @@ -1674,7 +1674,7 @@ ngx_http_add_listening(ngx_conf_t *cf, ngx_http_conf_addr_t *addr) ngx_http_core_loc_conf_t *clcf; ngx_http_core_srv_conf_t *cscf; - ls = ngx_create_listening(cf, addr->opt.sockaddr, addr->opt.socklen); + ls = ngx_create_listening(cf, &addr->opt.u.sockaddr, addr->opt.socklen); if (ls == NULL) { return NULL; } @@ -1743,7 +1743,7 @@ ngx_http_add_addrs(ngx_conf_t *cf, ngx_http_port_t *hport, for (i = 0; i < hport->naddrs; i++) { - sin = (struct sockaddr_in *) addr[i].opt.sockaddr; + sin = &addr[i].opt.u.sockaddr_in; addrs[i].addr = sin->sin_addr.s_addr; addrs[i].conf.default_server = addr[i].default_server; #if (NGX_HTTP_SSL) @@ -1804,7 +1804,7 @@ ngx_http_add_addrs6(ngx_conf_t *cf, ngx_http_port_t *hport, for (i = 0; i < hport->naddrs; i++) { - sin6 = (struct sockaddr_in6 *) addr[i].opt.sockaddr; + sin6 = &addr[i].opt.u.sockaddr_in6; addrs6[i].addr6 = sin6->sin6_addr; addrs6[i].conf.default_server = addr[i].default_server; #if (NGX_HTTP_SSL) diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c index edd294fed..83779a455 100644 --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -2850,7 +2850,7 @@ ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) if (!conf->listen) { ngx_memzero(&lsopt, sizeof(ngx_http_listen_opt_t)); - sin = (struct sockaddr_in *) &lsopt.sockaddr; + sin = &lsopt.u.sockaddr_in; sin->sin_family = AF_INET; #if (NGX_WIN32) @@ -2867,7 +2867,7 @@ ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) lsopt.sndbuf = -1; lsopt.wildcard = 1; - (void) ngx_sock_ntop((struct sockaddr *) &lsopt.sockaddr, lsopt.addr, + (void) ngx_sock_ntop(&lsopt.u.sockaddr, lsopt.addr, NGX_SOCKADDR_STRLEN, 1); if (ngx_http_add_listen(cf, conf, &lsopt) == NGX_OK) { @@ -3275,7 +3275,7 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) ngx_memzero(&lsopt, sizeof(ngx_http_listen_opt_t)); - ngx_memcpy(lsopt.sockaddr, u.sockaddr, u.socklen); + ngx_memcpy(&lsopt.u.sockaddr, u.sockaddr, u.socklen); lsopt.socklen = u.socklen; lsopt.backlog = NGX_LISTEN_BACKLOG; @@ -3283,7 +3283,7 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) lsopt.sndbuf = -1; lsopt.wildcard = u.wildcard; - (void) ngx_sock_ntop((struct sockaddr *) &lsopt.sockaddr, lsopt.addr, + (void) ngx_sock_ntop(&lsopt.u.sockaddr, lsopt.addr, NGX_SOCKADDR_STRLEN, 1); for (n = 2; n < cf->args->nelts; n++) { @@ -3380,7 +3380,7 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY) struct sockaddr *sa; - sa = (struct sockaddr *) lsopt.sockaddr; + sa = &lsopt.u.sockaddr; if (sa->sa_family == AF_INET6) { diff --git a/src/http/ngx_http_core_module.h b/src/http/ngx_http_core_module.h index c240f252c..9ed490a60 100644 --- a/src/http/ngx_http_core_module.h +++ b/src/http/ngx_http_core_module.h @@ -43,7 +43,18 @@ typedef struct ngx_http_core_loc_conf_s ngx_http_core_loc_conf_t; typedef struct { - u_char sockaddr[NGX_SOCKADDRLEN]; + union { + struct sockaddr sockaddr; + struct sockaddr_in sockaddr_in; +#if (NGX_HAVE_INET6) + struct sockaddr_in6 sockaddr_in6; +#endif +#if (NGX_HAVE_UNIX_DOMAIN) + struct sockaddr_un sockaddr_un; +#endif + u_char sockaddr_data[NGX_SOCKADDRLEN]; + } u; + socklen_t socklen; unsigned set:1; |