Re: [PATCH] [CLEANUP] Remove unnecessary casts

From: Simon Horman <horms#verge.net.au>
Date: Mon, 27 Jun 2011 08:36:03 +0900


On Sat, Jun 25, 2011 at 09:13:52PM +0200, Willy Tarreau wrote:
> Hi Simon,
>
> On Fri, Jun 24, 2011 at 03:11:37PM +0900, Simon Horman wrote:
> > There is no need to cast when going to or from void *
>
> Sometimes the void* is used as an easy cast (this is dirty but handy).
> This was the case here :
>
> > @@ -1266,9 +1266,9 @@ acl_fetch_src(struct proxy *px, struct session *l4, void *l7, int dir,
> > {
> > test->i = l4->si[0].addr.c.from.ss_family;
> > if (test->i == AF_INET)
> > - test->ptr = (void *)&((struct sockaddr_in *)&l4->si[0].addr.c.from)->sin_addr;
> > + test->ptr = &((struct sockaddr_in *)&l4->si[0].addr.c.from)->sin_addr;
> > else if (test->i == AF_INET6)
> > - test->ptr = (void *)&((struct sockaddr_in6 *)(&l4->si[0].addr.c.from))->sin6_addr;
> > + test->ptr = &((struct sockaddr_in6 *)(&l4->si[0].addr.c.from))->sin6_addr;
> > else
> > return 0;
> >
> > @@ -1327,9 +1327,9 @@ acl_fetch_dst(struct proxy *px, struct session *l4, void *l7, int dir,
> >
> > test->i = l4->si[0].addr.c.to.ss_family;
> > if (test->i == AF_INET)
> > - test->ptr = (void *)&((struct sockaddr_in *)&l4->si[0].addr.c.to)->sin_addr;
> > + test->ptr = &((struct sockaddr_in *)&l4->si[0].addr.c.to)->sin_addr;
> > else if (test->i == AF_INET6)
> > - test->ptr = (void *)&((struct sockaddr_in6 *)(&l4->si[0].addr.c.to))->sin6_addr;
> > + test->ptr = &((struct sockaddr_in6 *)(&l4->si[0].addr.c.to))->sin6_addr;
> > else
> > return 0;
>
> These 2 hunks cause the following warnings :
>
> src/proto_tcp.c: In function `acl_fetch_src':
> src/proto_tcp.c:1269: warning: assignment from incompatible pointer type
> src/proto_tcp.c:1271: warning: assignment from incompatible pointer type
> src/proto_tcp.c: In function `acl_fetch_dst':
> src/proto_tcp.c:1330: warning: assignment from incompatible pointer type
> src/proto_tcp.c:1332: warning: assignment from incompatible pointer type
>
> In fact test->ptr is declared as a char* so I have changed the cast from
> void* to char* and it's now OK.

Thanks, sorry for not catching that. Received on 2011/06/27 01:36

This archive was generated by hypermail 2.2.0 : 2011/06/27 01:45 CEST