[PATCH] cast results of ngx_ssl_get_connection to right type

Maxim Dounin mdounin at mdounin.ru
Tue Oct 2 10:09:52 UTC 2012


Hello!

On Tue, Oct 02, 2012 at 12:09:32PM +1000, Daniel Black wrote:

> 
> cast the output of the ngx_ssl_get_connection to (ngx_connection_t *) since by default the macro returns a void *.
> 
> This is so we can ngx_ssl_get_connection(ssl_ctx)->log directly that assigning it to an intermediate. It will also generate a warning if we use the wrong variable type.
> 
> -- 
> Daniel Black

> Author: Daniel Black <daniel.black at openquery.com>
> Date:   Mon Oct 1 17:46:49 2012 +1000
> 
>     cast the output of the ngx_ssl_get_connection to (ngx_connection_t *) since by default it is a void *. Any user of the macro will need to cast it anyway
> 
> diff --git a/src/event/ngx_event_openssl.h b/src/event/ngx_event_openssl.h
> index 3315ffb..50cc7f5 100644
> --- a/src/event/ngx_event_openssl.h
> +++ b/src/event/ngx_event_openssl.h
> @@ -123,7 +123,7 @@ ngx_int_t ngx_ssl_set_session(ngx_connection_t *c, ngx_ssl_session_t *session);
>  #define ngx_ssl_get_session(c)      SSL_get1_session(c->ssl->connection)
>  #define ngx_ssl_free_session        SSL_SESSION_free
>  #define ngx_ssl_get_connection(ssl_conn)                                      \
> -    SSL_get_ex_data(ssl_conn, ngx_ssl_connection_index)
> +    ((ngx_connection_t *) SSL_get_ex_data(ssl_conn, ngx_ssl_connection_index))
>  
>  
>  ngx_int_t ngx_ssl_get_protocol(ngx_connection_t *c, ngx_pool_t *pool,

I would rather not, thanks.  Assigning to an intermediate variable 
is something required anyway in most cases, and even if it's not - 
it makes code much more readable.

-- 
Maxim Dounin
http://nginx.com/support.html



More information about the nginx-devel mailing list