diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2011-11-19 10:23:24 -0800 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2011-12-09 17:37:09 -0800 |
commit | 46f3ef4460aa2c1c2cba22897694a1cea572d506 (patch) | |
tree | 8946f6fc1c623d40783992dfe2ae9383e1bcc707 | |
parent | fb3ef5844d392f70cc6bd9b0d8770ca17bde1428 (diff) |
Replace malloc(strlen) + strcpy sets with strdup calls
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Mark Kettenis <kettenis@openbsd.org>
Reviewed-by: James Cloos <cloos@jhcloos.com>
-rw-r--r-- | src/sm_client.c | 5 | ||||
-rw-r--r-- | src/sm_genid.c | 6 | ||||
-rw-r--r-- | src/sm_manager.c | 7 | ||||
-rw-r--r-- | src/sm_misc.c | 24 |
4 files changed, 9 insertions, 33 deletions
diff --git a/src/sm_client.c b/src/sm_client.c index 70511c1..faf2b9f 100644 --- a/src/sm_client.c +++ b/src/sm_client.c @@ -249,10 +249,7 @@ SmcOpenConnection(char *networkIdsList, SmPointer context, *clientIdRet = reply.client_id; - smcConn->client_id = (char *) malloc ( - strlen (*clientIdRet) + 1); - - strcpy (smcConn->client_id, *clientIdRet); + smcConn->client_id = strdup (*clientIdRet); } else { diff --git a/src/sm_genid.c b/src/sm_genid.c index ffeab7e..0a09276 100644 --- a/src/sm_genid.c +++ b/src/sm_genid.c @@ -139,8 +139,7 @@ SmsGenerateClientID(SmsConn smsConn) temp[1] = '\0'; uuid_unparse_lower(uuid, &temp[1]); - if ((id = malloc (strlen (temp) + 1)) != NULL) - strcpy (id, temp); + id = strdup (temp); return id; #else @@ -243,8 +242,7 @@ SmsGenerateClientID(SmsConn smsConn) if (++sequence > 9999) sequence = 0; - if ((id = malloc (strlen (temp) + 1)) != NULL) - strcpy (id, temp); + id = strdup (temp); return (id); # else diff --git a/src/sm_manager.c b/src/sm_manager.c index 14b2bea..9e0d187 100644 --- a/src/sm_manager.c +++ b/src/sm_manager.c @@ -72,8 +72,7 @@ _SmsProtocolSetupProc (IceConn iceConn, { const char *str = "Memory allocation failed"; - if ((*failureReasonRet = (char *) malloc (strlen (str) + 1)) != NULL) - strcpy (*failureReasonRet, str); + *failureReasonRet = strdup (str); return (0); } @@ -187,13 +186,11 @@ SmsRegisterClientReply(SmsConn smsConn, char *clientId) smRegisterClientReplyMsg *pMsg; char *pData; - if ((smsConn->client_id = (char *) malloc (strlen (clientId) + 1)) == NULL) + if ((smsConn->client_id = strdup (clientId)) == NULL) { return (0); } - strcpy (smsConn->client_id, clientId); - extra = ARRAY8_BYTES (strlen (clientId)); IceGetHeaderExtra (iceConn, _SmsOpcode, SM_RegisterClientReply, diff --git a/src/sm_misc.c b/src/sm_misc.c index bdef3dd..c081611 100644 --- a/src/sm_misc.c +++ b/src/sm_misc.c @@ -104,33 +104,21 @@ SmcProtocolRevision(SmcConn smcConn) char * SmcVendor(SmcConn smcConn) { - char *string = (char *) malloc (strlen (smcConn->vendor) + 1); - - strcpy (string, smcConn->vendor); - - return (string); + return strdup(smcConn->vendor); } char * SmcRelease(SmcConn smcConn) { - char *string = (char *) malloc (strlen (smcConn->release) + 1); - - strcpy (string, smcConn->release); - - return (string); + return strdup(smcConn->release); } char * SmcClientID(SmcConn smcConn) { - char *clientId = (char *) malloc (strlen (smcConn->client_id) + 1); - - strcpy (clientId, smcConn->client_id); - - return (clientId); + return strdup(smcConn->client_id); } @@ -163,11 +151,7 @@ SmsProtocolRevision(SmsConn smsConn) char * SmsClientID(SmsConn smsConn) { - char *clientId = (char *) malloc (strlen (smsConn->client_id) + 1); - - strcpy (clientId, smsConn->client_id); - - return (clientId); + return strdup(smsConn->client_id); } |