From e77dd2e4bc8227ebdab70b4233cb33ed690fa264 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 19 Nov 2011 10:33:15 -0800 Subject: Remove a bunch of unnecessary casts with malloc & free calls With modern compilers and headers, they cause more problems than they solve and just hide real issues. Signed-off-by: Alan Coopersmith Reviewed-by: Mark Kettenis Reviewed-by: James Cloos --- src/SMlibint.h | 10 +++++----- src/sm_client.c | 21 +++++++++------------ src/sm_manager.c | 4 ++-- src/sm_misc.c | 8 ++++---- src/sm_process.c | 10 +++++----- 5 files changed, 25 insertions(+), 28 deletions(-) diff --git a/src/SMlibint.h b/src/SMlibint.h index a478b48..c788739 100644 --- a/src/SMlibint.h +++ b/src/SMlibint.h @@ -236,7 +236,7 @@ in this Software without prior written authorization from The Open Group. #define EXTRACT_ARRAY8(_pBuf, _swap, _len, _array8) \ { \ EXTRACT_CARD32 (_pBuf, _swap, _len); \ - _array8 = (char *) malloc (_len + 1); \ + _array8 = malloc (_len + 1); \ memcpy (_array8, _pBuf, _len); \ _array8[_len] = '\0'; \ _pBuf += _len + PAD64 (4 + _len); \ @@ -246,7 +246,7 @@ in this Software without prior written authorization from The Open Group. { \ CARD32 _len; \ EXTRACT_CARD32 (_pBuf, _swap, _len); \ - _string = (char *) malloc (_len + 1); \ + _string = malloc (_len + 1); \ memcpy (_string, _pBuf, _len); \ _string[_len] = '\0'; \ _pBuf += _len + PAD64 (4 + _len); \ @@ -257,15 +257,15 @@ in this Software without prior written authorization from The Open Group. int _i, _j; \ EXTRACT_CARD32 (_pBuf, _swap, _count); \ _pBuf += 4; \ - _props = (SmProp **) malloc (_count * sizeof (SmProp *)); \ + _props = malloc (_count * sizeof (SmProp *)); \ for (_i = 0; _i < _count; _i++) \ { \ - _props[_i] = (SmProp *) malloc (sizeof (SmProp)); \ + _props[_i] = malloc (sizeof (SmProp)); \ EXTRACT_ARRAY8_AS_STRING (_pBuf, _swap, _props[_i]->name); \ EXTRACT_ARRAY8_AS_STRING (_pBuf, _swap, _props[_i]->type); \ EXTRACT_CARD32 (_pBuf, _swap, _props[_i]->num_vals); \ _pBuf += 4; \ - _props[_i]->vals = (SmPropValue *) malloc ( \ + _props[_i]->vals = malloc ( \ _props[_i]->num_vals * sizeof (SmPropValue)); \ for (_j = 0; _j < _props[_i]->num_vals; _j++) \ { \ diff --git a/src/sm_client.c b/src/sm_client.c index faf2b9f..23d8e32 100644 --- a/src/sm_client.c +++ b/src/sm_client.c @@ -138,7 +138,7 @@ SmcOpenConnection(char *networkIdsList, SmPointer context, return (NULL); } - if ((smcConn = (SmcConn) malloc (sizeof (struct _SmcConn))) == NULL) + if ((smcConn = malloc (sizeof (struct _SmcConn))) == NULL) { if (errorStringRet && errorLength > 0) { strncpy (errorStringRet, "Can't malloc", errorLength); @@ -158,7 +158,7 @@ SmcOpenConnection(char *networkIdsList, SmPointer context, setupstat == IceProtocolSetupIOError) { IceCloseConnection (iceConn); - free ((char *) smcConn); + free (smcConn); return (NULL); } else if (setupstat == IceProtocolAlreadyActive) @@ -169,7 +169,7 @@ SmcOpenConnection(char *networkIdsList, SmPointer context, * may not already have XSMP active on it. */ - free ((char *) smcConn); + free (smcConn); if (errorStringRet && errorLength > 0) { strncpy (errorStringRet, "Internal error in IceOpenConnection", errorLength); @@ -235,7 +235,7 @@ SmcOpenConnection(char *networkIdsList, SmPointer context, } free (smcConn->vendor); free (smcConn->release); - free ((char *) smcConn); + free (smcConn); return (NULL); } @@ -330,13 +330,13 @@ SmcCloseConnection(SmcConn smcConn, int count, char **reasonMsgs) while (ptr) { next = ptr->next; - free ((char *) ptr); + free (ptr); ptr = next; } } - free ((char *) smcConn); + free (smcConn); if (closeStatus == IceClosedNow) statusRet = SmcClosedNow; @@ -419,8 +419,7 @@ SmcGetProperties(SmcConn smcConn, SmcPropReplyProc propReplyProc, IceConn iceConn = smcConn->iceConn; _SmcPropReplyWait *wait, *ptr; - if ((wait = (_SmcPropReplyWait *) malloc ( - sizeof (_SmcPropReplyWait))) == NULL) + if ((wait = malloc (sizeof (_SmcPropReplyWait))) == NULL) { return (0); } @@ -454,8 +453,7 @@ SmcInteractRequest(SmcConn smcConn, int dialogType, smInteractRequestMsg *pMsg; _SmcInteractWait *wait, *ptr; - if ((wait = (_SmcInteractWait *) malloc ( - sizeof (_SmcInteractWait))) == NULL) + if ((wait = malloc (sizeof (_SmcInteractWait))) == NULL) { return (0); } @@ -534,8 +532,7 @@ SmcRequestSaveYourselfPhase2(SmcConn smcConn, wait = smcConn->phase2_wait; else { - if ((wait = (_SmcPhase2Wait *) malloc ( - sizeof (_SmcPhase2Wait))) == NULL) + if ((wait = malloc (sizeof (_SmcPhase2Wait))) == NULL) { return (0); } diff --git a/src/sm_manager.c b/src/sm_manager.c index 9e0d187..d28c0c5 100644 --- a/src/sm_manager.c +++ b/src/sm_manager.c @@ -68,7 +68,7 @@ _SmsProtocolSetupProc (IceConn iceConn, * Allocate new SmsConn. */ - if ((smsConn = (SmsConn) malloc (sizeof (struct _SmsConn))) == NULL) + if ((smsConn = malloc (sizeof (struct _SmsConn))) == NULL) { const char *str = "Memory allocation failed"; @@ -335,5 +335,5 @@ SmsCleanUp(SmsConn smsConn) if (smsConn->client_id) free (smsConn->client_id); - free ((char *) smsConn); + free (smsConn); } diff --git a/src/sm_misc.c b/src/sm_misc.c index c081611..83d1259 100644 --- a/src/sm_misc.c +++ b/src/sm_misc.c @@ -54,11 +54,11 @@ SmFreeProperty(SmProp *prop) { for (i = 0; i < prop->num_vals; i++) if (prop->vals[i].value) - free ((char *) prop->vals[i].value); - free ((char *) prop->vals); + free (prop->vals[i].value); + free (prop->vals); } - free ((char *) prop); + free (prop); } } @@ -77,7 +77,7 @@ SmFreeReasons(int count, char **reasonMsgs) for (i = 0; i < count; i++) free (reasonMsgs[i]); - free ((char *) reasonMsgs); + free (reasonMsgs); } } diff --git a/src/sm_process.c b/src/sm_process.c index b8f1b2c..651ddef 100644 --- a/src/sm_process.c +++ b/src/sm_process.c @@ -267,7 +267,7 @@ _SmcProcessMessage(IceConn iceConn, IcePointer clientData, int opcode, (*smcConn->phase2_wait->phase2_proc) (smcConn, smcConn->phase2_wait->client_data); - free ((char *) smcConn->phase2_wait); + free (smcConn->phase2_wait); smcConn->phase2_wait = NULL; } break; @@ -290,7 +290,7 @@ _SmcProcessMessage(IceConn iceConn, IcePointer clientData, int opcode, (*smcConn->interact_waits->interact_proc) (smcConn, smcConn->interact_waits->client_data); - free ((char *) smcConn->interact_waits); + free (smcConn->interact_waits); smcConn->interact_waits = next; } break; @@ -393,7 +393,7 @@ _SmcProcessMessage(IceConn iceConn, IcePointer clientData, int opcode, (*smcConn->prop_reply_waits->prop_reply_proc) (smcConn, smcConn->prop_reply_waits->client_data, numProps, props); - free ((char *) smcConn->prop_reply_waits); + free (smcConn->prop_reply_waits); smcConn->prop_reply_waits = next; IceDisposeCompleteMessage (iceConn, pStart); @@ -752,7 +752,7 @@ _SmsProcessMessage(IceConn iceConn, IcePointer clientData, int opcode, pData = pStart + 8; - reasonMsgs = (char **) malloc (count * sizeof (char *)); + reasonMsgs = malloc (count * sizeof (char *)); for (i = 0; i < count; i++) EXTRACT_ARRAY8_AS_STRING (pData, swap, reasonMsgs[i]); @@ -839,7 +839,7 @@ _SmsProcessMessage(IceConn iceConn, IcePointer clientData, int opcode, pData = pStart + 8; - propNames = (char **) malloc (count * sizeof (char *)); + propNames = malloc (count * sizeof (char *)); for (i = 0; i < count; i++) EXTRACT_ARRAY8_AS_STRING (pData, swap, propNames[i]); -- cgit v1.2.1