diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2011-11-30 18:40:46 -0800 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2011-12-06 11:18:07 -0800 |
commit | a04a45cb94f7f569e6dd77df93258fa167d0a4ea (patch) | |
tree | 449089b4192273a91703035c5c62ead005788a66 | |
parent | a0bfb4fefd20b396e3d88eff0c60602fc436dad5 (diff) |
Remove unnecessary casts on malloc, calloc & free calls
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Mark Kettenis <kettenis@openbsd.org>
-rw-r--r-- | Xtrans.c | 10 | ||||
-rw-r--r-- | Xtranslcl.c | 27 | ||||
-rw-r--r-- | Xtranssock.c | 32 | ||||
-rw-r--r-- | Xtranstli.c | 10 | ||||
-rw-r--r-- | Xtransutil.c | 13 |
5 files changed, 43 insertions, 49 deletions
@@ -143,7 +143,7 @@ TRANS(FreeConnInfo) (XtransConnInfo ciptr) if (ciptr->port) free (ciptr->port); - free ((char *) ciptr); + free (ciptr); } @@ -939,7 +939,7 @@ TRANS(GetMyAddr) (XtransConnInfo ciptr, int *familyp, int *addrlenp, *familyp = ciptr->family; *addrlenp = ciptr->addrlen; - if ((*addrp = (Xtransaddr *) malloc (ciptr->addrlen)) == NULL) + if ((*addrp = malloc (ciptr->addrlen)) == NULL) { prmsg (1,"GetMyAddr: malloc failed\n"); return -1; @@ -959,7 +959,7 @@ TRANS(GetPeerAddr) (XtransConnInfo ciptr, int *familyp, int *addrlenp, *familyp = ciptr->family; *addrlenp = ciptr->peeraddrlen; - if ((*addrp = (Xtransaddr *) malloc (ciptr->peeraddrlen)) == NULL) + if ((*addrp = malloc (ciptr->peeraddrlen)) == NULL) { prmsg (1,"GetPeerAddr: malloc failed\n"); return -1; @@ -1128,7 +1128,7 @@ TRANS(MakeAllCOTSServerListeners) (char *port, int *partial, int *count_ret, if (*count_ret > 0) { - if ((*ciptrs_ret = (XtransConnInfo *) malloc ( + if ((*ciptrs_ret = malloc ( *count_ret * sizeof (XtransConnInfo))) == NULL) { return -1; @@ -1226,7 +1226,7 @@ TRANS(MakeAllCLTSServerListeners) (char *port, int *partial, int *count_ret, if (*count_ret > 0) { - if ((*ciptrs_ret = (XtransConnInfo *) malloc ( + if ((*ciptrs_ret = malloc ( *count_ret * sizeof (XtransConnInfo))) == NULL) { return -1; diff --git a/Xtranslcl.c b/Xtranslcl.c index 925ba01..5beef7c 100644 --- a/Xtranslcl.c +++ b/Xtranslcl.c @@ -152,7 +152,7 @@ TRANS(FillAddrInfo)(XtransConnInfo ciptr, char *sun_path, char *peer_sun_path) ciptr->family = AF_UNIX; ciptr->addrlen = sizeof (struct sockaddr_un); - if ((sunaddr = (struct sockaddr_un *) malloc (ciptr->addrlen)) == NULL) + if ((sunaddr = malloc (ciptr->addrlen)) == NULL) { prmsg(1,"FillAddrInfo: failed to allocate memory for addr\n"); return 0; @@ -174,12 +174,11 @@ TRANS(FillAddrInfo)(XtransConnInfo ciptr, char *sun_path, char *peer_sun_path) ciptr->peeraddrlen = sizeof (struct sockaddr_un); - if ((p_sunaddr = (struct sockaddr_un *) malloc ( - ciptr->peeraddrlen)) == NULL) + if ((p_sunaddr = malloc (ciptr->peeraddrlen)) == NULL) { prmsg(1, "FillAddrInfo: failed to allocate memory for peer addr\n"); - free ((char *) sunaddr); + free (sunaddr); ciptr->addr = NULL; return 0; @@ -613,7 +612,7 @@ TRANS(PTSAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status) */ newciptr->addrlen=ciptr->addrlen; - if( (newciptr->addr=(char *)malloc(newciptr->addrlen)) == NULL ) { + if( (newciptr->addr = malloc(newciptr->addrlen)) == NULL ) { prmsg(1,"PTSAccept: failed to allocate memory for peer addr\n"); close(newfd); *status = TRANS_ACCEPT_BAD_MALLOC; @@ -623,7 +622,7 @@ TRANS(PTSAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status) memcpy(newciptr->addr,ciptr->addr,newciptr->addrlen); newciptr->peeraddrlen=sizeof(struct sockaddr_un); - if( (sunaddr=(struct sockaddr_un *)malloc(newciptr->peeraddrlen)) == NULL ) { + if( (sunaddr = malloc(newciptr->peeraddrlen)) == NULL ) { prmsg(1,"PTSAccept: failed to allocate memory for peer addr\n"); free(newciptr->addr); close(newfd); @@ -885,7 +884,7 @@ TRANS(NAMEDAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status) */ newciptr->family=ciptr->family; newciptr->addrlen=ciptr->addrlen; - if( (newciptr->addr=(char *)malloc(newciptr->addrlen)) == NULL ) { + if( (newciptr->addr = malloc(newciptr->addrlen)) == NULL ) { prmsg(1, "NAMEDAccept: failed to allocate memory for pipe addr\n"); close(str.fd); @@ -896,7 +895,7 @@ TRANS(NAMEDAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status) memcpy(newciptr->addr,ciptr->addr,newciptr->addrlen); newciptr->peeraddrlen=newciptr->addrlen; - if( (newciptr->peeraddr=(char *)malloc(newciptr->peeraddrlen)) == NULL ) { + if( (newciptr->peeraddr = malloc(newciptr->peeraddrlen)) == NULL ) { prmsg(1, "NAMEDAccept: failed to allocate memory for peer addr\n"); free(newciptr->addr); @@ -1223,7 +1222,7 @@ TRANS(SCOAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status) */ newciptr->addrlen=ciptr->addrlen; - if( (newciptr->addr=(char *)malloc(newciptr->addrlen)) == NULL ) { + if( (newciptr->addr = malloc(newciptr->addrlen)) == NULL ) { prmsg(1, "SCOAccept: failed to allocate memory for peer addr\n"); close(fd); @@ -1237,7 +1236,7 @@ TRANS(SCOAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status) #endif newciptr->peeraddrlen=newciptr->addrlen; - if( (newciptr->peeraddr=(char *)malloc(newciptr->peeraddrlen)) == NULL ) { + if( (newciptr->peeraddr = malloc(newciptr->peeraddrlen)) == NULL ) { prmsg(1, "SCOAccept: failed to allocate memory for peer addr\n"); free(newciptr->addr); @@ -1811,7 +1810,7 @@ TRANS(LocalOpenClient)(int type, char *protocol, char *host, char *port) */ #endif /* X11_t */ - if( (ciptr=(XtransConnInfo)calloc(1,sizeof(struct _XtransConnInfo))) == NULL ) + if( (ciptr = calloc(1,sizeof(struct _XtransConnInfo))) == NULL ) { prmsg(1,"LocalOpenClient: calloc(1,%lu) failed\n", sizeof(struct _XtransConnInfo)); @@ -1885,7 +1884,7 @@ TRANS(LocalOpenServer)(int type, char *protocol, char *host _X_UNUSED, char *por */ #endif /* X11_t */ - if( (ciptr=(XtransConnInfo)calloc(1,sizeof(struct _XtransConnInfo))) == NULL ) + if( (ciptr = calloc(1,sizeof(struct _XtransConnInfo))) == NULL ) { prmsg(1,"LocalOpenServer: calloc(1,%lu) failed\n", sizeof(struct _XtransConnInfo)); @@ -1939,7 +1938,7 @@ TRANS(LocalReopenServer)(int type, int index, int fd, char *port) prmsg(2,"LocalReopenServer(%d,%d,%d)\n", type, index, fd); - if( (ciptr=(XtransConnInfo)calloc(1,sizeof(struct _XtransConnInfo))) == NULL ) + if( (ciptr = calloc(1,sizeof(struct _XtransConnInfo))) == NULL ) { prmsg(1,"LocalReopenServer: calloc(1,%lu) failed\n", sizeof(struct _XtransConnInfo)); @@ -2171,7 +2170,7 @@ TRANS(LocalAccept)(XtransConnInfo ciptr, int *status) transptr=(LOCALtrans2dev *)ciptr->priv; - if( (newciptr=(XtransConnInfo)calloc(1,sizeof(struct _XtransConnInfo)))==NULL ) + if( (newciptr = calloc(1,sizeof(struct _XtransConnInfo)))==NULL ) { prmsg(1,"LocalAccept: calloc(1,%lu) failed\n", sizeof(struct _XtransConnInfo)); diff --git a/Xtranssock.c b/Xtranssock.c index bda2bcc..66f9862 100644 --- a/Xtranssock.c +++ b/Xtranssock.c @@ -315,7 +315,7 @@ TRANS(SocketINETGetAddr) (XtransConnInfo ciptr) * Everything looks good: fill in the XtransConnInfo structure. */ - if ((ciptr->addr = (char *) malloc (namelen)) == NULL) + if ((ciptr->addr = malloc (namelen)) == NULL) { prmsg (1, "SocketINETGetAddr: Can't allocate space for the addr\n"); @@ -382,7 +382,7 @@ TRANS(SocketINETGetPeerAddr) (XtransConnInfo ciptr) * Everything looks good: fill in the XtransConnInfo structure. */ - if ((ciptr->peeraddr = (char *) malloc (namelen)) == NULL) + if ((ciptr->peeraddr = malloc (namelen)) == NULL) { prmsg (1, "SocketINETGetPeerAddr: Can't allocate space for the addr\n"); @@ -404,8 +404,7 @@ TRANS(SocketOpen) (int i, int type) prmsg (3,"SocketOpen(%d,%d)\n", i, type); - if ((ciptr = (XtransConnInfo) calloc ( - 1, sizeof(struct _XtransConnInfo))) == NULL) + if ((ciptr = calloc (1, sizeof(struct _XtransConnInfo))) == NULL) { prmsg (1, "SocketOpen: malloc failed\n"); return NULL; @@ -425,7 +424,7 @@ TRANS(SocketOpen) (int i, int type) prmsg (2, "SocketOpen: socket() failed for %s\n", Sockettrans2devtab[i].transname); - free ((char *) ciptr); + free (ciptr); return NULL; } @@ -481,8 +480,7 @@ TRANS(SocketReopen) (int i _X_UNUSED, int type, int fd, char *port) } #endif /*SOCK_MAXADDRLEN*/ - if ((ciptr = (XtransConnInfo) calloc ( - 1, sizeof(struct _XtransConnInfo))) == NULL) + if ((ciptr = calloc (1, sizeof(struct _XtransConnInfo))) == NULL) { prmsg (1, "SocketReopen: malloc(ciptr) failed\n"); return NULL; @@ -490,7 +488,7 @@ TRANS(SocketReopen) (int i _X_UNUSED, int type, int fd, char *port) ciptr->fd = fd; - if ((addr = (struct sockaddr *) calloc (1, portlen + 2)) == NULL) { + if ((addr = calloc (1, portlen + 2)) == NULL) { prmsg (1, "SocketReopen: malloc(addr) failed\n"); free (ciptr); return NULL; @@ -498,7 +496,7 @@ TRANS(SocketReopen) (int i _X_UNUSED, int type, int fd, char *port) ciptr->addr = (char *) addr; ciptr->addrlen = portlen + 2; - if ((ciptr->peeraddr = (char *) calloc (1, portlen + 2)) == NULL) { + if ((ciptr->peeraddr = calloc (1, portlen + 2)) == NULL) { prmsg (1, "SocketReopen: malloc(portaddr) failed\n"); free (addr); free (ciptr); @@ -1138,7 +1136,7 @@ TRANS(SocketUNIXCreateListener) (XtransConnInfo ciptr, char *port, namelen = sizeof (sockname); /* this will always make it the same size */ - if ((ciptr->addr = (char *) malloc (namelen)) == NULL) + if ((ciptr->addr = malloc (namelen)) == NULL) { prmsg (1, "SocketUNIXCreateListener: Can't allocate space for the addr\n"); @@ -1252,8 +1250,7 @@ TRANS(SocketINETAccept) (XtransConnInfo ciptr, int *status) prmsg (2, "SocketINETAccept(%p,%d)\n", ciptr, ciptr->fd); - if ((newciptr = (XtransConnInfo) calloc ( - 1, sizeof(struct _XtransConnInfo))) == NULL) + if ((newciptr = calloc (1, sizeof(struct _XtransConnInfo))) == NULL) { prmsg (1, "SocketINETAccept: malloc failed\n"); *status = TRANS_ACCEPT_BAD_MALLOC; @@ -1329,8 +1326,7 @@ TRANS(SocketUNIXAccept) (XtransConnInfo ciptr, int *status) prmsg (2, "SocketUNIXAccept(%p,%d)\n", ciptr, ciptr->fd); - if ((newciptr = (XtransConnInfo) calloc ( - 1, sizeof(struct _XtransConnInfo))) == NULL) + if ((newciptr = calloc (1, sizeof(struct _XtransConnInfo))) == NULL) { prmsg (1, "SocketUNIXAccept: malloc() failed\n"); *status = TRANS_ACCEPT_BAD_MALLOC; @@ -1352,7 +1348,7 @@ TRANS(SocketUNIXAccept) (XtransConnInfo ciptr, int *status) * since this is unix domain. */ - if ((newciptr->addr = (char *) malloc (ciptr->addrlen)) == NULL) + if ((newciptr->addr = malloc (ciptr->addrlen)) == NULL) { prmsg (1, "SocketUNIXAccept: Can't allocate space for the addr\n"); @@ -1370,7 +1366,7 @@ TRANS(SocketUNIXAccept) (XtransConnInfo ciptr, int *status) newciptr->addrlen = ciptr->addrlen; memcpy (newciptr->addr, ciptr->addr, newciptr->addrlen); - if ((newciptr->peeraddr = (char *) malloc (ciptr->addrlen)) == NULL) + if ((newciptr->peeraddr = malloc (ciptr->addrlen)) == NULL) { prmsg (1, "SocketUNIXAccept: Can't allocate space for the addr\n"); @@ -2053,8 +2049,8 @@ TRANS(SocketUNIXConnect) (XtransConnInfo ciptr, char *host, char *port) * since this is unix domain. */ - if ((ciptr->addr = (char *) malloc(namelen)) == NULL || - (ciptr->peeraddr = (char *) malloc(namelen)) == NULL) + if ((ciptr->addr = malloc(namelen)) == NULL || + (ciptr->peeraddr = malloc(namelen)) == NULL) { prmsg (1, "SocketUNIXCreateListener: Can't allocate space for the addr\n"); diff --git a/Xtranstli.c b/Xtranstli.c index cbb7d4b..397c946 100644 --- a/Xtranstli.c +++ b/Xtranstli.c @@ -169,7 +169,7 @@ TRANS(TLIGetAddr)(XtransConnInfo ciptr) if( ciptr->addr ) free(ciptr->addr); - if( (ciptr->addr=(char *)malloc(netbuf.len)) == NULL ) + if( (ciptr->addr = malloc(netbuf.len)) == NULL ) { prmsg(1, "TLIGetAddr: Can't allocate space for the addr\n"); return -1; @@ -218,7 +218,7 @@ TRANS(TLIGetPeerAddr)(XtransConnInfo ciptr) if( ciptr->peeraddr ) free(ciptr->peeraddr); - if( (ciptr->peeraddr=(char *)malloc(netbuf.len)) == NULL ) + if( (ciptr->peeraddr = malloc(netbuf.len)) == NULL ) { prmsg(1, "TLIGetPeerAddr: Can't allocate space for the addr\n"); @@ -312,7 +312,7 @@ TRANS(TLIOpen)(char *device) prmsg(3,"TLIOpen(%s)\n", device); - if( (ciptr=(XtransConnInfo)calloc(1,sizeof(struct _XtransConnInfo))) == NULL ) + if( (ciptr = calloc(1,sizeof(struct _XtransConnInfo))) == NULL ) { prmsg(1, "TLIOpen: calloc failed\n"); return NULL; @@ -345,7 +345,7 @@ TRANS(TLIReopen)(char *device, int fd, char *port) return NULL; } - if( (ciptr=(XtransConnInfo)calloc(1,sizeof(struct _XtransConnInfo))) == NULL ) + if( (ciptr = calloc(1,sizeof(struct _XtransConnInfo))) == NULL ) { prmsg(1, "TLIReopen: calloc failed\n"); return NULL; @@ -720,7 +720,7 @@ TRANS(TLICreateListener)(XtransConnInfo ciptr, struct t_bind *req) * Everything looks good: fill in the XtransConnInfo structure. */ - if( (ciptr->addr=(char *)malloc(ret->addr.len)) == NULL ) + if( (ciptr->addr = malloc(ret->addr.len)) == NULL ) { prmsg(1, "TLICreateListener: Unable to allocate space for the address\n"); diff --git a/Xtransutil.c b/Xtransutil.c index 4128990..52c937b 100644 --- a/Xtransutil.c +++ b/Xtransutil.c @@ -197,11 +197,11 @@ TRANS(ConvertAddress)(int *familyp, int *addrlenp, Xtransaddr **addrp) if (len > 0) { if (*addrp && *addrlenp < (len + 1)) { - free ((char *) *addrp); + free (*addrp); *addrp = NULL; } if (!*addrp) - *addrp = (Xtransaddr *) malloc (len + 1); + *addrp = malloc (len + 1); if (*addrp) { strcpy ((char *) *addrp, hostnamebuf); *addrlenp = len; @@ -212,7 +212,7 @@ TRANS(ConvertAddress)(int *familyp, int *addrlenp, Xtransaddr **addrp) else { if (*addrp) - free ((char *) *addrp); + free (*addrp); *addrp = NULL; *addrlenp = 0; } @@ -255,7 +255,7 @@ TRANS(GetMyNetworkId) (XtransConnInfo ciptr) case AF_UNIX: { struct sockaddr_un *saddr = (struct sockaddr_un *) addr; - networkId = (char *) malloc (3 + strlen (transName) + + networkId = malloc (3 + strlen (transName) + strlen (hostnamebuf) + strlen (saddr->sun_path)); sprintf (networkId, "%s/%s:%s", transName, hostnamebuf, saddr->sun_path); @@ -285,7 +285,7 @@ TRANS(GetMyNetworkId) (XtransConnInfo ciptr) portnum = ntohs (saddr->sin_port); snprintf (portnumbuf, sizeof(portnumbuf), "%d", portnum); - networkId = (char *) malloc (3 + strlen (transName) + + networkId = malloc (3 + strlen (transName) + strlen (hostnamebuf) + strlen (portnumbuf)); sprintf (networkId, "%s/%s:%s", transName, hostnamebuf, portnumbuf); break; @@ -418,8 +418,7 @@ TRANS(GetPeerNetworkId) (XtransConnInfo ciptr) } - hostname = (char *) malloc ( - strlen (ciptr->transptr->TransName) + strlen (addr) + 2); + hostname = malloc (strlen (ciptr->transptr->TransName) + strlen (addr) + 2); strcpy (hostname, ciptr->transptr->TransName); strcat (hostname, "/"); if (addr) |