This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Get rid of some type-punning warnings


Andreas Jaeger wrote:
*buffer, size_t buflen, int *errnop,
>  			   int *h_errnop)
>  {
> -  querybuf *host_buffer, *orig_host_buffer;
> +  union 
> +  {
> +    querybuf *buf;
> +    void *ptr;
> +  } host_buffer;
> +  querybuf *orig_host_buffer;

Why do you use void* for ptr and not u_char*?


> -  n = __libc_res_nsearch (&_res, name, C_IN, type, host_buffer->buf,
> -			  1024, (u_char **) &host_buffer);
> +  n = __libc_res_nsearch (&_res, name, C_IN, type, host_buffer.buf->buf,
> +			  1024, (u_char **) &host_buffer.ptr);

In this situation you could simlpy use &host_buffer.ptr.


>
> ============================================================
> Index: resolv/nss_dns/dns-network.c
> --- resolv/nss_dns/dns-network.c	19 Nov 2002 06:40:16 -0000	1.17
> +++ resolv/nss_dns/dns-network.c	28 Dec 2002 15:35:11 -0000
> @@ -110,7 +110,12 @@ _nss_dns_getnetbyname_r (const char *nam
>  			 int *herrnop)
>  {
>    /* Return entry for network with NAME.  */
> -  querybuf *net_buffer, *orig_net_buffer;
> +  union 
> +  {
> +    querybuf *buf;
> +    void *ptr;
> +  } net_buffer;
> +  querybuf *orig_net_buffer;
>    int anslen;
>    char *qbuf;
>    enum nss_status status;
> @@ -120,25 +125,25 @@ _nss_dns_getnetbyname_r (const char *nam
>  
>    qbuf = strdupa (name);
>  
> -  net_buffer = orig_net_buffer = (querybuf *) alloca (1024);
> +  net_buffer.buf = orig_net_buffer = (querybuf *) alloca (1024);
>  
> -  anslen = __libc_res_nsearch (&_res, qbuf, C_IN, T_PTR, net_buffer->buf,
> -			       1024, (u_char **) &net_buffer);
> +  anslen = __libc_res_nsearch (&_res, qbuf, C_IN, T_PTR, net_buffer.buf->buf,
> +			       1024, (u_char **) &net_buffer.buf);


And here you use &net_buffer.buf?  I thought this is what you want to avoid?


Please check the patch again.  Make sure that if uchar* can be used it
is used and remove all the casts.

-- 
--------------.                        ,-.            444 Castro Street
Ulrich Drepper \    ,-----------------'   \ Mountain View, CA 94041 USA
Red Hat         `--' drepper at redhat.com `---------------------------


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]