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,7 +1087,7 @@ RecordAddClientToRCAP(RecordClientsAndProtocolPtr pRCAP, XID clientspec)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
XID *pNewIDs =
|
XID *pNewIDs =
|
||||||
xallocarray(pRCAP->sizeClients + CLIENT_ARRAY_GROWTH_INCREMENT,
|
calloc(pRCAP->sizeClients + CLIENT_ARRAY_GROWTH_INCREMENT,
|
||||||
sizeof(XID));
|
sizeof(XID));
|
||||||
if (!pNewIDs)
|
if (!pNewIDs)
|
||||||
return;
|
return;
|
||||||
|
@ -1218,7 +1218,7 @@ RecordCanonicalizeClientSpecifiers(XID *pClientspecs, int *pNumClientspecs,
|
||||||
for (i = 0; i < numClients; i++) {
|
for (i = 0; i < numClients; i++) {
|
||||||
if (pClientspecs[i] == XRecordAllClients || pClientspecs[i] == XRecordCurrentClients) { /* expand All/Current */
|
if (pClientspecs[i] == XRecordAllClients || pClientspecs[i] == XRecordCurrentClients) { /* expand All/Current */
|
||||||
int j, nc;
|
int j, nc;
|
||||||
XID *pCanon = xallocarray(currentMaxClients + 1, sizeof(XID));
|
XID *pCanon = calloc(currentMaxClients + 1, sizeof(XID));
|
||||||
|
|
||||||
if (!pCanon)
|
if (!pCanon)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -1418,7 +1418,7 @@ static int
|
||||||
RecordAllocIntervals(SetInfoPtr psi, int nIntervals)
|
RecordAllocIntervals(SetInfoPtr psi, int nIntervals)
|
||||||
{
|
{
|
||||||
assert(!psi->intervals);
|
assert(!psi->intervals);
|
||||||
psi->intervals = xallocarray(nIntervals, sizeof(RecordSetInterval));
|
psi->intervals = calloc(nIntervals, sizeof(RecordSetInterval));
|
||||||
if (!psi->intervals)
|
if (!psi->intervals)
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
memset(psi->intervals, 0, nIntervals * sizeof(RecordSetInterval));
|
memset(psi->intervals, 0, nIntervals * sizeof(RecordSetInterval));
|
||||||
|
@ -1579,7 +1579,7 @@ RecordRegisterClients(RecordContextPtr pContext, ClientPtr client,
|
||||||
* range for extension replies.
|
* range for extension replies.
|
||||||
*/
|
*/
|
||||||
maxSets = RI_PREDEFSETS + 2 * stuff->nRanges;
|
maxSets = RI_PREDEFSETS + 2 * stuff->nRanges;
|
||||||
si = xallocarray(maxSets, sizeof(SetInfoRec));
|
si = calloc(maxSets, sizeof(SetInfoRec));
|
||||||
if (!si) {
|
if (!si) {
|
||||||
err = BadAlloc;
|
err = BadAlloc;
|
||||||
goto bailout;
|
goto bailout;
|
||||||
|
@ -2143,7 +2143,7 @@ ProcRecordGetContext(ClientPtr client)
|
||||||
|
|
||||||
/* allocate and initialize space for record range info */
|
/* allocate and initialize space for record range info */
|
||||||
|
|
||||||
pRangeInfo = xallocarray(nRCAPs, sizeof(GetContextRangeInfoRec));
|
pRangeInfo = calloc(nRCAPs, sizeof(GetContextRangeInfoRec));
|
||||||
if (!pRangeInfo && nRCAPs > 0)
|
if (!pRangeInfo && nRCAPs > 0)
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
for (i = 0; i < nRCAPs; i++) {
|
for (i = 0; i < nRCAPs; i++) {
|
||||||
|
@ -2712,8 +2712,7 @@ RecordAClientStateChange(CallbackListPtr *pcbl, void *nulldata,
|
||||||
/* RecordDisableContext modifies contents of ppAllContexts. */
|
/* RecordDisableContext modifies contents of ppAllContexts. */
|
||||||
if (!(numContextsCopy = numContexts))
|
if (!(numContextsCopy = numContexts))
|
||||||
break;
|
break;
|
||||||
ppAllContextsCopy = xallocarray(numContextsCopy,
|
ppAllContextsCopy = calloc(numContextsCopy, sizeof(RecordContextPtr));
|
||||||
sizeof(RecordContextPtr));
|
|
||||||
assert(ppAllContextsCopy);
|
assert(ppAllContextsCopy);
|
||||||
memcpy(ppAllContextsCopy, ppAllContexts,
|
memcpy(ppAllContextsCopy, ppAllContexts,
|
||||||
numContextsCopy * sizeof(RecordContextPtr));
|
numContextsCopy * sizeof(RecordContextPtr));
|
||||||
|
|
|
@ -312,7 +312,7 @@ IntervalListCreateSet(RecordSetInterval * pIntervals, int nIntervals,
|
||||||
CARD16 first;
|
CARD16 first;
|
||||||
|
|
||||||
if (nIntervals > 0) {
|
if (nIntervals > 0) {
|
||||||
stackIntervals = xallocarray(nIntervals, sizeof(RecordSetInterval));
|
stackIntervals = calloc(nIntervals, sizeof(RecordSetInterval));
|
||||||
if (!stackIntervals)
|
if (!stackIntervals)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue