diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2011-11-19 00:08:18 -0800 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2011-11-19 00:08:18 -0800 |
commit | c44cb256ce8660c9d529374b7596531dad1a5376 (patch) | |
tree | 2fd6f7c72680f3eaeb16bf8443844ab64ddae904 | |
parent | 42a2a79b3e1f5c9cbb076743965eba8268733989 (diff) |
Remove a bunch of unnecessary casts with malloc, free & memcpy calls
With modern compilers and headers, they cause more problems than they
solve and just hide real issues.
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r-- | io.c | 34 | ||||
-rw-r--r-- | misc.c | 20 | ||||
-rw-r--r-- | pm.c | 13 | ||||
-rw-r--r-- | transport.c | 6 | ||||
-rw-r--r-- | xfwp.h | 2 |
5 files changed, 35 insertions, 40 deletions
@@ -87,10 +87,10 @@ RemoveFDFromServerListenArray ( FD_CLR (server_array[i]->client_listen_fd, rinit); (void) close (server_array[i]->client_listen_fd); if (server_array[i]->x_server_hostport) - free ((char *) server_array[i]->x_server_hostport); + free (server_array[i]->x_server_hostport); if (server_array[i]->listen_port_string) - free ((char *) server_array[i]->listen_port_string); - free ((char *) server_array[i]); + free (server_array[i]->listen_port_string); + free (server_array[i]); server_array[i] = NULL; break; } @@ -383,8 +383,7 @@ ProcessNewPMConnection ( * pm_conn_array; this saves us much troublesome linked-list * management!] */ - if ((pm_conn_array[pm_idx] = - (struct pm_conn_buf *) malloc(sizeof(struct pm_conn_buf))) == NULL) + if ((pm_conn_array[pm_idx] = malloc(sizeof(struct pm_conn_buf))) == NULL) { (void) fprintf (stderr, "malloc - PM connection object\n"); return; @@ -608,7 +607,7 @@ ProcessNewClientConnection ( * If configured authorization succeeds, go ahead and * allocate a client_conn_buf struct for client connection */ - if ((client_conn_array[temp_sock_fd] = (struct client_conn_buf *) + if ((client_conn_array[temp_sock_fd] = malloc(sizeof (struct client_conn_buf))) == NULL) { (void) fprintf (stderr, "malloc - client connection buffer\n"); @@ -635,7 +634,7 @@ ProcessNewClientConnection ( * allocate a buffer for the X server connection * and create the association between client and server */ - if ((client_conn_array[server_fd] = (struct client_conn_buf *) + if ((client_conn_array[server_fd] = malloc(sizeof (struct client_conn_buf))) == NULL) { (void) fprintf (stderr, "malloc - server connection buffer\n"); @@ -756,10 +755,10 @@ ProcessClientWaiting ( bufP = client_conn_array[idx]->writebuf; - memcpy(bufP, (char *) &client, sizeof(client)); + memcpy(bufP, &client, sizeof(client)); bufP += sizeof(client); - memcpy(bufP, (char *) conn_auth_name, conn_auth_namelen); + memcpy(bufP, conn_auth_name, conn_auth_namelen); bufP += conn_auth_namelen; bzero(bufP, name_remainder); @@ -1009,7 +1008,7 @@ ProcessServerReply ( * allocate the padded buffer */ if ((server_reason_padded = - (char *) malloc (server_reason_len + + malloc (server_reason_len + server_reason_remainder)) == NULL) { (void) fprintf (stderr, "malloc - server reason\n"); @@ -1048,10 +1047,10 @@ ProcessServerReply ( /* * load the padded reason */ - bzero((char *) server_reason_padded, + bzero(server_reason_padded, server_reason_len + server_reason_remainder); - memcpy((char *) server_reason_padded, - (char *) server_reason + memcpy(server_reason_padded, + server_reason [(int) client_conn_array[client_fd]->readbuf[0]], server_reason_len); /* @@ -1059,13 +1058,12 @@ ProcessServerReply ( * be sent to the client next time the writables are * processed (again, to avoid blocking) */ - memcpy((char *) client_conn_array[client_fd]->readbuf, - (char *) &prefix, + memcpy(client_conn_array[client_fd]->readbuf, + &prefix, sizeof(prefix)); - memcpy((char *) client_conn_array[client_fd]->readbuf + - sizeof(prefix), - (char *) server_reason_padded, + memcpy(client_conn_array[client_fd]->readbuf + sizeof(prefix), + server_reason_padded, server_reason_len + server_reason_remainder); client_conn_array[client_fd]->rbytes = sizeof(prefix) + @@ -266,7 +266,7 @@ doConfigPermitDeny( config_file_data = config_info->config_file_data; if ((config_file_data[line_number]->permit_deny = - (char *) malloc (strlen(result) + 1)) == NULL) + malloc (strlen(result) + 1)) == NULL) { (void) fprintf(stderr, "malloc - config rule (permit/deny keyword)\n"); return 0; @@ -290,7 +290,7 @@ doConfigPermitDeny( if (doVerifyHostMaskToken(token)) { if ((config_file_data[line_number]->source_hostname = - (char *) malloc (strlen(result) + 1)) == NULL) + malloc (strlen(result) + 1)) == NULL) { (void) fprintf(stderr, "malloc - config rule (source host)\n"); return 0; @@ -321,7 +321,7 @@ doConfigPermitDeny( if (doVerifyHostMaskToken(token)) { if ((config_file_data[line_number]->source_netmask = - (char *) malloc (strlen(result) + 1)) == NULL) + malloc (strlen(result) + 1)) == NULL) { (void) fprintf(stderr, "malloc - config rule (source netmask)\n"); return 0; @@ -349,7 +349,7 @@ doConfigPermitDeny( if (doVerifyHostMaskToken(token)) { if ((config_file_data[line_number]->dest_hostname = - (char *) malloc (strlen(result) + 1)) == NULL) + malloc (strlen(result) + 1)) == NULL) { (void) fprintf(stderr, "malloc - config rule (destination host)\n"); return 0; @@ -377,7 +377,7 @@ doConfigPermitDeny( if (doVerifyHostMaskToken(token)) { if ((config_file_data[line_number]->dest_netmask = - (char *) malloc (strlen(result) + 1)) == NULL) + malloc (strlen(result) + 1)) == NULL) { (void) fprintf(stderr, "malloc - config rule (destination mask)\n"); return 0; @@ -402,7 +402,7 @@ doConfigPermitDeny( if (!strcmp("eq", result)) { if ((config_file_data[line_number]->operator = - (char *) malloc (strlen(result) + 1)) == NULL) + malloc (strlen(result) + 1)) == NULL) { (void) fprintf(stderr, "malloc - config rule (op)\n"); return 0; @@ -427,7 +427,7 @@ doConfigPermitDeny( (!strncmp("cd", result, 2))) { if ((config_file_data[line_number]->service = - (char *) malloc (strlen(result) + 1)) == NULL) + malloc (strlen(result) + 1)) == NULL) { (void) fprintf(stderr, "malloc - config rule (service)\n"); return 0; @@ -1228,7 +1228,7 @@ doCheckServerList( /* * allocate and return the listen_port_string */ - if ((*listen_port_string = (char *) malloc + if ((*listen_port_string = malloc (strlen(server_array[list_counter]->listen_port_string) + 1)) == NULL) { @@ -1396,7 +1396,7 @@ doProcessInputArgs ( #endif #endif - client_conn_array = (struct client_conn_buf **) + client_conn_array = malloc (config_info->num_client_conns * sizeof (struct client_conn_buf *)); if (!client_conn_array) { @@ -1406,7 +1406,7 @@ doProcessInputArgs ( if (!config_info->num_pm_conns) config_info->num_pm_conns = MAX_PM_CONNS; - pm_conn_array = (struct pm_conn_buf **) + pm_conn_array = malloc (config_info->num_client_conns * sizeof (struct pm_conn_buf *)); if (!pm_conn_array) { @@ -159,7 +159,7 @@ void FWPprocessMessages( if (authLen > 0) { EXTRACT_STRING (pData, swap, authName); - authData = (char *) malloc (authLen); + authData = malloc (authLen); memcpy (authData, pData, authLen); } #ifdef DEBUG @@ -201,7 +201,7 @@ void FWPprocessMessages( } memset(&server_sockaddr_in, 0, sizeof(server_sockaddr_in)); memset(&dummy_sockaddr_in, 0, sizeof(dummy_sockaddr_in)); - memcpy((char *) &server_sockaddr_in.sin_addr, + memcpy(&server_sockaddr_in.sin_addr, hostptr->h_addr, hostptr->h_length); @@ -211,7 +211,7 @@ void FWPprocessMessages( * NOTE: source configuration will always match (see XFWP man * page) unless sysadmin explicitly chooses to deny */ - memcpy((char *) &dummy_sockaddr_in.sin_addr, + memcpy(&dummy_sockaddr_in.sin_addr, hostptr->h_addr, hostptr->h_length); @@ -270,7 +270,7 @@ void FWPprocessMessages( *colon = ':'; if (hostent && hostent->h_name) { - tmpAddress = (char *) malloc (strlen (hostent->h_name) + + tmpAddress = malloc (strlen (hostent->h_name) + strlen (colon) + 1); (void) sprintf (tmpAddress, "%s%s", hostent->h_name, colon); serverAddress = tmpAddress; @@ -411,8 +411,7 @@ FWPprotocolSetupProc( * IceProcessMessages() */ struct clientDataStruct * client_data; - if ((client_data = (struct clientDataStruct *) - malloc (sizeof (struct clientDataStruct))) == NULL) + if ((client_data = malloc (sizeof (struct clientDataStruct))) == NULL) { (void) fprintf(stderr, "malloc - client data object\n"); return (0); @@ -465,7 +464,7 @@ doSetupPMListen( /* * Create space for pm_listen_array */ - *pm_listen_array = (int *) malloc (num_fds_returned * sizeof (int *)); + *pm_listen_array = malloc (num_fds_returned * sizeof (int *)); if (!pm_listen_array) { (void) fprintf (stderr, "malloc - pm_listen_array\n"); diff --git a/transport.c b/transport.c index e7fe444..d6ac1c1 100644 --- a/transport.c +++ b/transport.c @@ -86,8 +86,7 @@ doSetupRemClientListen( * can't use the PM connection fd as an index into this array, since * there could be multiple servers per PM connection */ - if ((server_array[this_server] = - (struct server_list *) malloc(sizeof(struct server_list))) == NULL) + if ((server_array[this_server] = malloc(sizeof(struct server_list))) == NULL) { (void) fprintf(stderr,"malloc - server_array\n"); return FAILURE; @@ -189,8 +188,7 @@ doSetupRemClientListen( * string equals address of host on which FWP is running * plus ":<listen_port - X_SERVER_PORT_BASE> (up to xxx)" */ - if (((*listen_port_string) = - (char *) malloc (strlen(hostname) + 10)) == NULL) + if (((*listen_port_string) = malloc (strlen(hostname) + 10)) == NULL) { (void) fprintf(stderr, "malloc - proxy address\n"); goto returnFailure; @@ -286,7 +286,7 @@ extern int SitePolicyPermit; { \ CARD16 _len; \ EXTRACT_CARD16 (_pBuf, _swap, _len); \ - _string = (char *) malloc (_len + 1); \ + _string = malloc (_len + 1); \ memcpy (_string, _pBuf, _len); \ _string[_len] = '\0'; \ _pBuf += _len; \ |