summaryrefslogtreecommitdiff
path: root/Xtrans.c
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2011-11-30 18:11:15 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2011-12-06 11:18:00 -0800
commita0bfb4fefd20b396e3d88eff0c60602fc436dad5 (patch)
tree6924964157285000819bdf6816ace59475fd218b /Xtrans.c
parentb89e1b45198c48996750b5da3d715c10f974243f (diff)
Replace malloc(strlen)+strcpy with strdup
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com> Reviewed-by: Mark Kettenis <kettenis@openbsd.org>
Diffstat (limited to 'Xtrans.c')
-rw-r--r--Xtrans.c26
1 files changed, 7 insertions, 19 deletions
diff --git a/Xtrans.c b/Xtrans.c
index 007b54f..97de39b 100644
--- a/Xtrans.c
+++ b/Xtrans.c
@@ -212,8 +212,7 @@ TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port)
/* Copy the string so it can be changed */
- tmpptr = mybuf = (char *) malloc (strlen (address) + 1);
- strcpy (mybuf, address);
+ tmpptr = mybuf = strdup (address);
/* Parse the string to get each component */
@@ -346,7 +345,7 @@ TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port)
* string space for them.
*/
- if ((*protocol = (char *) malloc(strlen (_protocol) + 1)) == NULL)
+ if ((*protocol = strdup (_protocol)) == NULL)
{
/* Malloc failed */
*port = NULL;
@@ -355,10 +354,8 @@ TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port)
free (tmpptr);
return 0;
}
- else
- strcpy (*protocol, _protocol);
- if ((*host = (char *) malloc (strlen (_host) + 1)) == NULL)
+ if ((*host = strdup (_host)) == NULL)
{
/* Malloc failed */
*port = NULL;
@@ -367,11 +364,9 @@ TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port)
*protocol = NULL;
free (tmpptr);
return 0;
- }
- else
- strcpy (*host, _host);
+ }
- if ((*port = (char *) malloc (strlen (_port) + 1)) == NULL)
+ if ((*port = strdup (_port)) == NULL)
{
/* Malloc failed */
*port = NULL;
@@ -382,8 +377,6 @@ TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port)
free (tmpptr);
return 0;
}
- else
- strcpy (*port, _port);
free (tmpptr);
@@ -523,15 +516,13 @@ TRANS(Reopen) (int type, int trans_id, int fd, char *port)
return NULL;
}
- if ((save_port = (char *) malloc (strlen (port) + 1)) == NULL)
+ if ((save_port = strdup (port)) == NULL)
{
prmsg (1,"Reopen: Unable to malloc port string\n");
return NULL;
}
- strcpy (save_port, port);
-
/* Get a new XtransConnInfo object */
switch (type)
@@ -653,13 +644,10 @@ TRANS(GetReopenInfo) (XtransConnInfo ciptr,
*trans_id = Xtransports[i].transport_id;
*fd = ciptr->fd;
- if ((*port = (char *) malloc (strlen (ciptr->port) + 1)) == NULL)
+ if ((*port = strdup (ciptr->port)) == NULL)
return 0;
else
- {
- strcpy (*port, ciptr->port);
return 1;
- }
}
return 0;