diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2015-03-21 13:42:12 -0700 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2015-04-21 16:57:08 -0700 |
commit | 1c56ac63c040280498c4a9d67b48c35b60070821 (patch) | |
tree | ab1073d348cb1acf0523ede3e1f2fa73f3b5fdb6 /record | |
parent | b9e665c8b2f048feb3064ce412e0b3e9eb6797b0 (diff) |
Convert top level extensions to new *allocarray functions
v2: remove now useless parentheses
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
Diffstat (limited to 'record')
-rw-r--r-- | record/record.c | 35 | ||||
-rw-r--r-- | record/set.c | 4 |
2 files changed, 17 insertions, 22 deletions
diff --git a/record/record.c b/record/record.c index 0a466e279..1caf3f1db 100644 --- a/record/record.c +++ b/record/record.c @@ -1074,19 +1074,19 @@ RecordAddClientToRCAP(RecordClientsAndProtocolPtr pRCAP, XID clientspec) { if (pRCAP->numClients == pRCAP->sizeClients) { if (pRCAP->clientIDsSeparatelyAllocated) { - XID *pNewIDs = (XID *) realloc(pRCAP->pClientIDs, - (pRCAP->sizeClients + - CLIENT_ARRAY_GROWTH_INCREMENT) * - sizeof(XID)); + XID *pNewIDs = + reallocarray(pRCAP->pClientIDs, + pRCAP->sizeClients + CLIENT_ARRAY_GROWTH_INCREMENT, + sizeof(XID)); if (!pNewIDs) return; pRCAP->pClientIDs = pNewIDs; pRCAP->sizeClients += CLIENT_ARRAY_GROWTH_INCREMENT; } else { - XID *pNewIDs = (XID *) malloc((pRCAP->sizeClients + - CLIENT_ARRAY_GROWTH_INCREMENT) * - sizeof(XID)); + XID *pNewIDs = + xallocarray(pRCAP->sizeClients + CLIENT_ARRAY_GROWTH_INCREMENT, + sizeof(XID)); if (!pNewIDs) return; memcpy(pNewIDs, pRCAP->pClientIDs, pRCAP->numClients * sizeof(XID)); @@ -1217,7 +1217,7 @@ RecordCanonicalizeClientSpecifiers(XID *pClientspecs, int *pNumClientspecs, for (i = 0; i < numClients; i++) { if (pClientspecs[i] == XRecordAllClients || pClientspecs[i] == XRecordCurrentClients) { /* expand All/Current */ int j, nc; - XID *pCanon = (XID *) malloc(sizeof(XID) * (currentMaxClients + 1)); + XID *pCanon = xallocarray(currentMaxClients + 1, sizeof(XID)); if (!pCanon) return NULL; @@ -1421,8 +1421,7 @@ static int RecordAllocIntervals(SetInfoPtr psi, int nIntervals) { assert(!psi->intervals); - psi->intervals = (RecordSetInterval *) - malloc(nIntervals * sizeof(RecordSetInterval)); + psi->intervals = xallocarray(nIntervals, sizeof(RecordSetInterval)); if (!psi->intervals) return BadAlloc; memset(psi->intervals, 0, nIntervals * sizeof(RecordSetInterval)); @@ -1584,7 +1583,7 @@ RecordRegisterClients(RecordContextPtr pContext, ClientPtr client, * range for extension replies. */ maxSets = PREDEFSETS + 2 * stuff->nRanges; - si = (SetInfoPtr) malloc(sizeof(SetInfoRec) * maxSets); + si = xallocarray(maxSets, sizeof(SetInfoRec)); if (!si) { err = BadAlloc; goto bailout; @@ -1853,8 +1852,8 @@ ProcRecordCreateContext(ClientPtr client) /* make sure there is room in ppAllContexts to store the new context */ - ppNewAllContexts = (RecordContextPtr *) - realloc(ppAllContexts, sizeof(RecordContextPtr) * (numContexts + 1)); + ppNewAllContexts = + reallocarray(ppAllContexts, numContexts + 1, sizeof(RecordContextPtr)); if (!ppNewAllContexts) goto bailout; ppAllContexts = ppNewAllContexts; @@ -1971,8 +1970,7 @@ RecordAllocRanges(GetContextRangeInfoPtr pri, int nRanges) #define SZINCR 8 newsize = max(pri->size + SZINCR, nRanges); - pNewRange = (xRecordRange *) realloc(pri->pRanges, - newsize * sizeof(xRecordRange)); + pNewRange = reallocarray(pri->pRanges, newsize, sizeof(xRecordRange)); if (!pNewRange) return BadAlloc; @@ -2150,9 +2148,7 @@ ProcRecordGetContext(ClientPtr client) /* allocate and initialize space for record range info */ - pRangeInfo = - (GetContextRangeInfoPtr) malloc(nRCAPs * - sizeof(GetContextRangeInfoRec)); + pRangeInfo = xallocarray(nRCAPs, sizeof(GetContextRangeInfoRec)); if (!pRangeInfo && nRCAPs > 0) return BadAlloc; for (i = 0; i < nRCAPs; i++) { @@ -2733,7 +2729,8 @@ RecordAClientStateChange(CallbackListPtr *pcbl, void *nulldata, /* RecordDisableContext modifies contents of ppAllContexts. */ numContextsCopy = numContexts; - ppAllContextsCopy = malloc(numContextsCopy * sizeof(RecordContextPtr)); + ppAllContextsCopy = xallocarray(numContextsCopy, + sizeof(RecordContextPtr)); assert(ppAllContextsCopy); memcpy(ppAllContextsCopy, ppAllContexts, numContextsCopy * sizeof(RecordContextPtr)); diff --git a/record/set.c b/record/set.c index 34faa617e..e0db385b9 100644 --- a/record/set.c +++ b/record/set.c @@ -303,9 +303,7 @@ IntervalListCreateSet(RecordSetInterval * pIntervals, int nIntervals, CARD16 first; if (nIntervals > 0) { - stackIntervals = - (RecordSetInterval *) malloc(sizeof(RecordSetInterval) * - nIntervals); + stackIntervals = xallocarray(nIntervals, sizeof(RecordSetInterval)); if (!stackIntervals) return NULL; |