diff options
author | Alan Coopersmith <alan.coopersmith@sun.com> | 2007-04-05 15:05:52 -0700 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@sun.com> | 2007-04-05 15:05:52 -0700 |
commit | cd900e40b5676874d076c35466fd7baa6a49b1f6 (patch) | |
tree | c04168c7db0fcb3e401f09ce4d30a13dd65e7712 | |
parent | 27f9a9324d58c9a7472c724c62f5b7ea0e1f4681 (diff) |
Replace many malloc(strlen()); strcpy() pairs with strdup()
-rw-r--r-- | src/accept.c | 5 | ||||
-rw-r--r-- | src/connect.c | 4 | ||||
-rw-r--r-- | src/iceauth.c | 26 | ||||
-rw-r--r-- | src/listen.c | 9 | ||||
-rw-r--r-- | src/misc.c | 22 | ||||
-rw-r--r-- | src/process.c | 26 | ||||
-rw-r--r-- | src/register.c | 30 | ||||
-rw-r--r-- | src/setauth.c | 22 |
8 files changed, 43 insertions, 101 deletions
diff --git a/src/accept.c b/src/accept.c index df2b258..d54ffd4 100644 --- a/src/accept.c +++ b/src/accept.c @@ -92,8 +92,7 @@ IceAcceptStatus *statusRet; iceConn->send_sequence = 0; iceConn->receive_sequence = 0; - iceConn->connection_string = (char *) malloc ( - strlen (listenObj->network_id) + 1); + iceConn->connection_string = strdup(listenObj->network_id); if (iceConn->connection_string == NULL) { @@ -102,8 +101,6 @@ IceAcceptStatus *statusRet; *statusRet = IceAcceptBadMalloc; return (NULL); } - else - strcpy (iceConn->connection_string, listenObj->network_id); iceConn->vendor = NULL; iceConn->release = NULL; diff --git a/src/connect.c b/src/connect.c index 933c186..3874058 100644 --- a/src/connect.c +++ b/src/connect.c @@ -524,9 +524,7 @@ ConnectToPeer (char *networkIdsList, char **actualConnectionRet) * We need to return the actual network connection string */ - *actualConnectionRet = (char *) malloc (strlen (address) + 1); - strcpy (*actualConnectionRet, address); - + *actualConnectionRet = strdup(address); /* * Return the file descriptor diff --git a/src/iceauth.c b/src/iceauth.c index 38500a5..dcee7ed 100644 --- a/src/iceauth.c +++ b/src/iceauth.c @@ -135,12 +135,10 @@ char **errorStringRet; if (!data) { - char *tempstr = + const char *tempstr = "Could not find correct MIT-MAGIC-COOKIE-1 authentication"; - *errorStringRet = (char *) malloc (strlen (tempstr) + 1); - if (*errorStringRet) - strcpy (*errorStringRet, tempstr); + *errorStringRet = strdup(tempstr); return (IcePoAuthFailed); } @@ -161,11 +159,10 @@ char **errorStringRet; * a single pass authentication method. */ - char *tempstr = "MIT-MAGIC-COOKIE-1 authentication internal error"; + const char *tempstr = + "MIT-MAGIC-COOKIE-1 authentication internal error"; - *errorStringRet = (char *) malloc (strlen (tempstr) + 1); - if (*errorStringRet) - strcpy (*errorStringRet, tempstr); + *errorStringRet = strdup(tempstr); return (IcePoAuthFailed); } @@ -226,11 +223,10 @@ char **errorStringRet; } else { - char *tempstr = "MIT-MAGIC-COOKIE-1 authentication rejected"; + const char *tempstr + = "MIT-MAGIC-COOKIE-1 authentication rejected"; - *errorStringRet = (char *) malloc (strlen (tempstr) + 1); - if (*errorStringRet) - strcpy (*errorStringRet, tempstr); + *errorStringRet = strdup(tempstr); stat = IcePaAuthRejected; } @@ -246,12 +242,10 @@ char **errorStringRet; * always find a valid entry. */ - char *tempstr = + const char *tempstr = "MIT-MAGIC-COOKIE-1 authentication internal error"; - *errorStringRet = (char *) malloc (strlen (tempstr) + 1); - if (*errorStringRet) - strcpy (*errorStringRet, tempstr); + *errorStringRet = strdup(tempstr); return (IcePaAuthFailed); } diff --git a/src/listen.c b/src/listen.c index 9875f30..d3aa4b2 100644 --- a/src/listen.c +++ b/src/listen.c @@ -177,14 +177,7 @@ IceGetListenConnectionString (listenObj) IceListenObj listenObj; { - char *networkId; - - networkId = (char *) malloc (strlen (listenObj->network_id) + 1); - - if (networkId) - strcpy (networkId, listenObj->network_id); - - return (networkId); + return strdup(listenObj->network_id); } @@ -129,12 +129,7 @@ IceVendor (iceConn) IceConn iceConn; { - char *string = (char *) malloc (strlen (iceConn->vendor) + 1); - - if (string) - strcpy (string, iceConn->vendor); - - return (string); + return strdup(iceConn->vendor); } @@ -144,12 +139,7 @@ IceRelease (iceConn) IceConn iceConn; { - char *string = (char *) malloc (strlen (iceConn->release) + 1); - - if (string) - strcpy (string, iceConn->release); - - return (string); + return strdup(iceConn->release); } @@ -191,13 +181,7 @@ IceConn iceConn; { if (iceConn->connection_string) { - char *string = (char *) malloc ( - strlen (iceConn->connection_string) + 1); - - if (string) - strcpy (string, iceConn->connection_string); - - return (string); + return strdup(iceConn->connection_string); } else return (NULL); diff --git a/src/process.c b/src/process.c index 2a97dcb..416f1c6 100644 --- a/src/process.c +++ b/src/process.c @@ -615,7 +615,7 @@ IceReplyWaitInfo *replyWait; _IceConnectionError *errorReply = &(((_IceReply *) (replyWait->reply))->connection_error); char *errorStr = NULL; - char *tempstr; + const char *tempstr; char *prefix, *temp; invokeHandler = 0; @@ -627,16 +627,14 @@ IceReplyWaitInfo *replyWait; tempstr = "None of the ICE versions specified are supported"; - errorStr = (char *) malloc (strlen (tempstr) + 1); - strcpy (errorStr, tempstr); + errorStr = strdup(tempstr); break; case IceNoAuth: tempstr = "None of the authentication protocols specified are supported"; - errorStr = (char *) malloc (strlen (tempstr) + 1); - strcpy (errorStr, tempstr); + errorStr = strdup(tempstr); break; case IceSetupFailed: @@ -697,16 +695,14 @@ IceReplyWaitInfo *replyWait; temp = "None of the protocol versions specified are supported"; - errorStr = (char *) malloc (strlen (temp) + 1); - strcpy (errorStr, temp); + errorStr = strdup(temp); break; case IceNoAuth: temp = "None of the authentication protocols specified are supported"; - errorStr = (char *) malloc (strlen (temp) + 1); - strcpy (errorStr, temp); + errorStr = strdup(temp); break; case IceSetupFailed: @@ -1129,11 +1125,11 @@ IceReplyWaitInfo *replyWait; _IceConnectionError *errorReply = &(((_IceReply *) (replyWait->reply))->connection_error); - char *tempstr = "Received bad authIndex in the AuthRequired message"; + const char *tempstr + = "Received bad authIndex in the AuthRequired message"; char errIndex = (int) message->authIndex; - errorString = (char *) malloc (strlen (tempstr) + 1); - strcpy (errorString, tempstr); + errorString = strdup(tempstr); errorReply->type = ICE_CONNECTION_ERROR; errorReply->error_message = errorString; @@ -1159,11 +1155,11 @@ IceReplyWaitInfo *replyWait; _IceProtocolError *errorReply = &(((_IceReply *) (replyWait->reply))->protocol_error); - char *tempstr = "Received bad authIndex in the AuthRequired message"; + const char *tempstr + = "Received bad authIndex in the AuthRequired message"; char errIndex = (int) message->authIndex; - errorString = (char *) malloc (strlen (tempstr) + 1); - strcpy (errorString, tempstr); + errorString = strdup(tempstr); errorReply->type = ICE_PROTOCOL_ERROR; errorReply->error_message = errorString; diff --git a/src/register.c b/src/register.c index 20e60df..bcf95a2 100644 --- a/src/register.c +++ b/src/register.c @@ -85,8 +85,7 @@ IceIOErrorProc IOErrorProc; char *name; _IceProtocols[_IceLastMajorOpcode].protocol_name = name = - (char *) malloc (strlen (protocolName) + 1); - strcpy (name, protocolName); + strdup(protocolName); p = _IceProtocols[_IceLastMajorOpcode].orig_client = (_IcePoProtocol *) malloc (sizeof (_IcePoProtocol)); @@ -96,11 +95,8 @@ IceIOErrorProc IOErrorProc; opcodeRet = ++_IceLastMajorOpcode; } - p->vendor = (char *) malloc (strlen (vendor) + 1); - strcpy (p->vendor, vendor); - - p->release = (char *) malloc (strlen (release) + 1); - strcpy (p->release, release); + p->vendor = strdup(vendor); + p->release = strdup(release); p->version_count = versionCount; @@ -119,10 +115,7 @@ IceIOErrorProc IOErrorProc; for (i = 0; i < authCount; i++) { - p->auth_names[i] = - (char *) malloc (strlen (authNames[i]) + 1); - strcpy (p->auth_names[i], authNames[i]); - + p->auth_names[i] = strdup(authNames[i]); p->auth_procs[i] = authProcs[i]; } } @@ -197,8 +190,7 @@ IceIOErrorProc IOErrorProc; char *name; _IceProtocols[_IceLastMajorOpcode].protocol_name = name = - (char *) malloc (strlen (protocolName) + 1); - strcpy (name, protocolName); + strdup(protocolName); _IceProtocols[_IceLastMajorOpcode].orig_client = NULL; @@ -208,11 +200,8 @@ IceIOErrorProc IOErrorProc; opcodeRet = ++_IceLastMajorOpcode; } - p->vendor = (char *) malloc (strlen (vendor) + 1); - strcpy (p->vendor, vendor); - - p->release = (char *) malloc (strlen (release) + 1); - strcpy (p->release, release); + p->vendor = strdup(vendor); + p->release = strdup(release); p->version_count = versionCount; @@ -234,10 +223,7 @@ IceIOErrorProc IOErrorProc; for (i = 0; i < authCount; i++) { - p->auth_names[i] = - (char *) malloc (strlen (authNames[i]) + 1); - strcpy (p->auth_names[i], authNames[i]); - + p->auth_names[i] = strdup(authNames[i]); p->auth_procs[i] = authProcs[i]; } } diff --git a/src/setauth.c b/src/setauth.c index 4fd7718..8ed9cef 100644 --- a/src/setauth.c +++ b/src/setauth.c @@ -96,20 +96,14 @@ IceAuthDataEntry *entries; _IcePaAuthDataEntryCount++; } - _IcePaAuthDataEntries[j].protocol_name = (char *) malloc ( - strlen (entries[i].protocol_name) + 1); - strcpy (_IcePaAuthDataEntries[j].protocol_name, - entries[i].protocol_name); - - _IcePaAuthDataEntries[j].network_id = (char *) malloc ( - strlen (entries[i].network_id) + 1); - strcpy (_IcePaAuthDataEntries[j].network_id, - entries[i].network_id); - - _IcePaAuthDataEntries[j].auth_name = (char *) malloc ( - strlen (entries[i].auth_name) + 1); - strcpy (_IcePaAuthDataEntries[j].auth_name, - entries[i].auth_name); + _IcePaAuthDataEntries[j].protocol_name + = strdup(entries[i].protocol_name); + + _IcePaAuthDataEntries[j].network_id + = strdup(entries[i].network_id); + + _IcePaAuthDataEntries[j].auth_name + = strdup(entries[i].auth_name); _IcePaAuthDataEntries[j].auth_data_length = entries[i].auth_data_length; |