record: replace xallocarray() by calloc()
Only key difference that calloc(), in contrast to rellocarray(), is zero-initializing. The overhead is hard to measure on today's machines, and it's safer programming practise to always allocate zero-initialized, so one can't forget to do it explicitly. Cocci rule: @@ expression COUNT; expression LEN; @@ - xallocarray(COUNT,LEN) + calloc(COUNT,LEN) Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
parent
f25921f5fb
commit
7b24948dbf
|
@ -1087,8 +1087,8 @@ RecordAddClientToRCAP(RecordClientsAndProtocolPtr pRCAP, XID clientspec)
|
|||
}
|
||||
else {
|
||||
XID *pNewIDs =
|
||||
xallocarray(pRCAP->sizeClients + CLIENT_ARRAY_GROWTH_INCREMENT,
|
||||
sizeof(XID));
|
||||
calloc(pRCAP->sizeClients + CLIENT_ARRAY_GROWTH_INCREMENT,
|
||||
sizeof(XID));
|
||||
if (!pNewIDs)
|
||||
return;
|
||||
memcpy(pNewIDs, pRCAP->pClientIDs, pRCAP->numClients * sizeof(XID));
|
||||
|
@ -1218,7 +1218,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 = xallocarray(currentMaxClients + 1, sizeof(XID));
|
||||
XID *pCanon = calloc(currentMaxClients + 1, sizeof(XID));
|
||||
|
||||
if (!pCanon)
|
||||
return NULL;
|
||||
|
@ -1418,7 +1418,7 @@ static int
|
|||
RecordAllocIntervals(SetInfoPtr psi, int nIntervals)
|
||||
{
|
||||
assert(!psi->intervals);
|
||||
psi->intervals = xallocarray(nIntervals, sizeof(RecordSetInterval));
|
||||
psi->intervals = calloc(nIntervals, sizeof(RecordSetInterval));
|
||||
if (!psi->intervals)
|
||||
return BadAlloc;
|
||||
memset(psi->intervals, 0, nIntervals * sizeof(RecordSetInterval));
|
||||
|
@ -1579,7 +1579,7 @@ RecordRegisterClients(RecordContextPtr pContext, ClientPtr client,
|
|||
* range for extension replies.
|
||||
*/
|
||||
maxSets = RI_PREDEFSETS + 2 * stuff->nRanges;
|
||||
si = xallocarray(maxSets, sizeof(SetInfoRec));
|
||||
si = calloc(maxSets, sizeof(SetInfoRec));
|
||||
if (!si) {
|
||||
err = BadAlloc;
|
||||
goto bailout;
|
||||
|
@ -2143,7 +2143,7 @@ ProcRecordGetContext(ClientPtr client)
|
|||
|
||||
/* allocate and initialize space for record range info */
|
||||
|
||||
pRangeInfo = xallocarray(nRCAPs, sizeof(GetContextRangeInfoRec));
|
||||
pRangeInfo = calloc(nRCAPs, sizeof(GetContextRangeInfoRec));
|
||||
if (!pRangeInfo && nRCAPs > 0)
|
||||
return BadAlloc;
|
||||
for (i = 0; i < nRCAPs; i++) {
|
||||
|
@ -2712,8 +2712,7 @@ RecordAClientStateChange(CallbackListPtr *pcbl, void *nulldata,
|
|||
/* RecordDisableContext modifies contents of ppAllContexts. */
|
||||
if (!(numContextsCopy = numContexts))
|
||||
break;
|
||||
ppAllContextsCopy = xallocarray(numContextsCopy,
|
||||
sizeof(RecordContextPtr));
|
||||
ppAllContextsCopy = calloc(numContextsCopy, sizeof(RecordContextPtr));
|
||||
assert(ppAllContextsCopy);
|
||||
memcpy(ppAllContextsCopy, ppAllContexts,
|
||||
numContextsCopy * sizeof(RecordContextPtr));
|
||||
|
|
|
@ -312,7 +312,7 @@ IntervalListCreateSet(RecordSetInterval * pIntervals, int nIntervals,
|
|||
CARD16 first;
|
||||
|
||||
if (nIntervals > 0) {
|
||||
stackIntervals = xallocarray(nIntervals, sizeof(RecordSetInterval));
|
||||
stackIntervals = calloc(nIntervals, sizeof(RecordSetInterval));
|
||||
if (!stackIntervals)
|
||||
return NULL;
|
||||
|
||||
|
|
Loading…
Reference in New Issue