[PATCH:libSM 5/8] Replace malloc(strlen) + strcpy sets with strdup calls
Alan Coopersmith
alan.coopersmith at oracle.com
Mon Dec 5 20:06:18 PST 2011
Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
src/sm_client.c | 5 +----
src/sm_genid.c | 6 ++----
src/sm_manager.c | 7 ++-----
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 2ebebad..f46a317 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
@@ -242,8 +241,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);
}
--
1.7.3.2
More information about the xorg-devel
mailing list