Compare commits

...

32 Commits

Author SHA1 Message Date
Enrico Weigelt, metux IT consult a6eec961d8 os.h: drop obsolete xallocarray()
This macro isn't used anywhere (also not in drivers), so no need
to keep it around any longer.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-04-02 17:37:14 +00:00
Enrico Weigelt, metux IT consult 333bcfd40e panoramix: protect against allocaton failure
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-04-02 17:37:14 +00:00
Enrico Weigelt, metux IT consult 529e12fcd2 xwayland: protect from memory allocation failure
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-04-02 17:37:14 +00:00
Enrico Weigelt, metux IT consult 478653996a xwayland: 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>
2025-04-02 17:37:14 +00:00
Enrico Weigelt, metux IT consult 39b2354bbc xnest: protect from memory allocation failure
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-04-02 17:37:14 +00:00
Enrico Weigelt, metux IT consult 6a1ec27678 xnest: 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>
2025-04-02 17:37:14 +00:00
Enrico Weigelt, metux IT consult 75dc221459 xfree86: protect from memory allocation failure
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-04-02 17:37:14 +00:00
Enrico Weigelt, metux IT consult ea618f9bff xfree86: 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>
2025-04-02 17:37:14 +00:00
Enrico Weigelt, metux IT consult 654c7ce1df xvfb: protect from memory allocation failure
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-04-02 17:37:14 +00:00
Enrico Weigelt, metux IT consult 7f60953188 xvfb: 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>
2025-04-02 17:37:14 +00:00
Enrico Weigelt, metux IT consult a3f88ae029 kdrive: 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>
2025-04-02 17:37:14 +00:00
Enrico Weigelt, metux IT consult 784c0397e5 xkb: protect from memory allocation failure
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-04-02 17:37:14 +00:00
Enrico Weigelt, metux IT consult 39278054cb xkb: 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>
2025-04-02 17:37:14 +00:00
Enrico Weigelt, metux IT consult 33c0ab942f xfixes: 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>
2025-04-02 17:37:14 +00:00
Enrico Weigelt, metux IT consult d481c8311a render: 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>
2025-04-02 17:37:14 +00:00
Enrico Weigelt, metux IT consult 2263e514c4 record: protect from memory allocation failure
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-04-02 17:37:14 +00:00
Enrico Weigelt, metux IT consult 85eefbf721 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>
2025-04-02 17:37:14 +00:00
Enrico Weigelt, metux IT consult 538bfd4acb randr: 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>
2025-04-02 17:37:14 +00:00
Enrico Weigelt, metux IT consult a51511635c os: 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>
2025-04-02 17:37:14 +00:00
Enrico Weigelt, metux IT consult d819be0df9 miext: 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>
2025-04-02 17:37:14 +00:00
Enrico Weigelt, metux IT consult c7fb5c25bc mi: 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>
2025-04-02 17:37:14 +00:00
Enrico Weigelt, metux IT consult 4b0b459ac0 glamor: 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>
2025-04-02 17:37:14 +00:00
Enrico Weigelt, metux IT consult 30c22fb1ba fb: 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>
2025-04-02 17:37:14 +00:00
Enrico Weigelt, metux IT consult f5f23e8801 exa: protect from allocation failure
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-04-02 17:37:14 +00:00
Enrico Weigelt, metux IT consult 9a0388f988 exa: 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>
2025-04-02 17:37:14 +00:00
Enrico Weigelt, metux IT consult f909106adb dix: protect from allocation failure
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-04-02 17:37:14 +00:00
Enrico Weigelt, metux IT consult 6dac1cd970 dix: 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>
2025-04-02 17:37:14 +00:00
Enrico Weigelt, metux IT consult 1f4c810baa dbe: 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>
2025-04-02 17:37:14 +00:00
Enrico Weigelt, metux IT consult ebd36eeb05 xi: protect from allocation failure
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-04-02 17:37:14 +00:00
Enrico Weigelt, metux IT consult 349ba2c3f9 xi: 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>
2025-04-02 17:37:14 +00:00
Enrico Weigelt, metux IT consult ab150e8b52 xext: xres: protect from allocation failure
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-04-02 17:37:14 +00:00
Enrico Weigelt, metux IT consult 0263bc7c32 xext: 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>
2025-04-02 17:37:14 +00:00
85 changed files with 311 additions and 241 deletions

View File

@ -52,7 +52,7 @@ ht_create(int keySize,
ht->elements = 0;
ht->bucketBits = INITHASHSIZE;
numBuckets = 1 << ht->bucketBits;
ht->buckets = xallocarray(numBuckets, sizeof(*ht->buckets));
ht->buckets = calloc(numBuckets, sizeof(*ht->buckets));
ht->cdata = cdata;
if (ht->buckets) {
@ -93,7 +93,7 @@ double_size(HashTable ht)
int newNumBuckets = 1 << newBucketBits;
int c;
newBuckets = xallocarray(newNumBuckets, sizeof(*ht->buckets));
newBuckets = calloc(newNumBuckets, sizeof(*ht->buckets));
if (newBuckets) {
for (c = 0; c < newNumBuckets; ++c) {
xorg_list_init(&newBuckets[c]);

View File

@ -1374,7 +1374,6 @@ PanoramiXPolyPoint(ClientPtr client)
{
PanoramiXRes *gc, *draw;
int result, npoint, j;
xPoint *origPts;
Bool isRoot;
REQUEST(xPolyPointReq);
@ -1397,7 +1396,10 @@ PanoramiXPolyPoint(ClientPtr client)
isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root;
npoint = bytes_to_int32((client->req_len << 2) - sizeof(xPolyPointReq));
if (npoint > 0) {
origPts = xallocarray(npoint, sizeof(xPoint));
xPoint *origPts = calloc(npoint, sizeof(xPoint));
if (!origPts)
return BadAlloc;
memcpy((char *) origPts, (char *) &stuff[1], npoint * sizeof(xPoint));
FOR_NSCREENS_FORWARD(j) {
@ -1439,7 +1441,6 @@ PanoramiXPolyLine(ClientPtr client)
{
PanoramiXRes *gc, *draw;
int result, npoint, j;
xPoint *origPts;
Bool isRoot;
REQUEST(xPolyLineReq);
@ -1462,7 +1463,9 @@ PanoramiXPolyLine(ClientPtr client)
isRoot = IS_ROOT_DRAWABLE(draw);
npoint = bytes_to_int32((client->req_len << 2) - sizeof(xPolyLineReq));
if (npoint > 0) {
origPts = xallocarray(npoint, sizeof(xPoint));
xPoint *origPts = calloc(npoint, sizeof(xPoint));
if (!origPts)
return BadAlloc;
memcpy((char *) origPts, (char *) &stuff[1], npoint * sizeof(xPoint));
FOR_NSCREENS_FORWARD(j) {
@ -1504,7 +1507,6 @@ PanoramiXPolySegment(ClientPtr client)
{
int result, nsegs, i, j;
PanoramiXRes *gc, *draw;
xSegment *origSegs;
Bool isRoot;
REQUEST(xPolySegmentReq);
@ -1531,7 +1533,9 @@ PanoramiXPolySegment(ClientPtr client)
return BadLength;
nsegs >>= 3;
if (nsegs > 0) {
origSegs = xallocarray(nsegs, sizeof(xSegment));
xSegment *origSegs = calloc(nsegs, sizeof(xSegment));
if (!origSegs)
return BadAlloc;
memcpy((char *) origSegs, (char *) &stuff[1], nsegs * sizeof(xSegment));
FOR_NSCREENS_FORWARD(j) {
@ -1573,7 +1577,6 @@ PanoramiXPolyRectangle(ClientPtr client)
int result, nrects, i, j;
PanoramiXRes *gc, *draw;
Bool isRoot;
xRectangle *origRecs;
REQUEST(xPolyRectangleReq);
@ -1599,7 +1602,9 @@ PanoramiXPolyRectangle(ClientPtr client)
return BadLength;
nrects >>= 3;
if (nrects > 0) {
origRecs = xallocarray(nrects, sizeof(xRectangle));
xRectangle *origRecs = calloc(nrects, sizeof(xRectangle));
if (!origRecs)
return BadAlloc;
memcpy((char *) origRecs, (char *) &stuff[1],
nrects * sizeof(xRectangle));
FOR_NSCREENS_FORWARD(j) {
@ -1640,7 +1645,6 @@ PanoramiXPolyArc(ClientPtr client)
int result, narcs, i, j;
PanoramiXRes *gc, *draw;
Bool isRoot;
xArc *origArcs;
REQUEST(xPolyArcReq);
@ -1666,7 +1670,9 @@ PanoramiXPolyArc(ClientPtr client)
return BadLength;
narcs /= sizeof(xArc);
if (narcs > 0) {
origArcs = xallocarray(narcs, sizeof(xArc));
xArc *origArcs = calloc(narcs, sizeof(xArc));
if (!origArcs)
return BadAlloc;
memcpy((char *) origArcs, (char *) &stuff[1], narcs * sizeof(xArc));
FOR_NSCREENS_FORWARD(j) {
@ -1705,7 +1711,6 @@ PanoramiXFillPoly(ClientPtr client)
int result, count, j;
PanoramiXRes *gc, *draw;
Bool isRoot;
DDXPointPtr locPts;
REQUEST(xFillPolyReq);
@ -1728,7 +1733,9 @@ PanoramiXFillPoly(ClientPtr client)
count = bytes_to_int32((client->req_len << 2) - sizeof(xFillPolyReq));
if (count > 0) {
locPts = xallocarray(count, sizeof(DDXPointRec));
DDXPointPtr locPts = calloc(count, sizeof(DDXPointRec));
if (!locPts)
return BadAlloc;
memcpy((char *) locPts, (char *) &stuff[1],
count * sizeof(DDXPointRec));
FOR_NSCREENS_FORWARD(j) {
@ -1771,8 +1778,6 @@ PanoramiXPolyFillRectangle(ClientPtr client)
int result, things, i, j;
PanoramiXRes *gc, *draw;
Bool isRoot;
xRectangle *origRects;
REQUEST(xPolyFillRectangleReq);
REQUEST_AT_LEAST_SIZE(xPolyFillRectangleReq);
@ -1797,7 +1802,9 @@ PanoramiXPolyFillRectangle(ClientPtr client)
return BadLength;
things >>= 3;
if (things > 0) {
origRects = xallocarray(things, sizeof(xRectangle));
xRectangle *origRects = calloc(things, sizeof(xRectangle));
if (!origRects)
return BadAlloc;
memcpy((char *) origRects, (char *) &stuff[1],
things * sizeof(xRectangle));
FOR_NSCREENS_FORWARD(j) {
@ -1838,7 +1845,6 @@ PanoramiXPolyFillArc(ClientPtr client)
PanoramiXRes *gc, *draw;
Bool isRoot;
int result, narcs, i, j;
xArc *origArcs;
REQUEST(xPolyFillArcReq);
@ -1864,7 +1870,9 @@ PanoramiXPolyFillArc(ClientPtr client)
return BadLength;
narcs /= sizeof(xArc);
if (narcs > 0) {
origArcs = xallocarray(narcs, sizeof(xArc));
xArc *origArcs = calloc(narcs, sizeof(xArc));
if (!origArcs)
return BadAlloc;
memcpy((char *) origArcs, (char *) &stuff[1], narcs * sizeof(xArc));
FOR_NSCREENS_FORWARD(j) {
@ -2050,7 +2058,7 @@ PanoramiXGetImage(ClientPtr client)
if (linesPerBuf > h)
linesPerBuf = h;
}
if (!(pBuf = xallocarray(linesPerBuf, widthBytesLine)))
if (!(pBuf = calloc(linesPerBuf, widthBytesLine)))
return BadAlloc;
WriteReplyToClient(client, sizeof(xGetImageReply), &xgi);

View File

@ -828,7 +828,7 @@ ScreenSaverSetAttributes(ClientPtr client, xScreenSaverSetAttributesReq *stuff)
goto bail;
}
/* over allocate for override redirect */
pAttr->values = values = xallocarray(len + 1, sizeof(unsigned long));
pAttr->values = values = calloc(len + 1, sizeof(unsigned long));
if (!values) {
ret = BadAlloc;
goto bail;

View File

@ -991,7 +991,7 @@ ProcShapeGetRectangles(ClientPtr client)
nrects = RegionNumRects(region);
box = RegionRects(region);
rects = xallocarray(nrects, sizeof(xRectangle));
rects = calloc(nrects, sizeof(xRectangle));
if (!rects && nrects)
return BadAlloc;
for (i = 0; i < nrects; i++, box++) {

View File

@ -650,7 +650,7 @@ SyncAwaitTriggerFired(SyncTrigger * pTrigger)
pAwaitUnion = (SyncAwaitUnion *) pAwait->pHeader;
numwaits = pAwaitUnion->header.num_waitconditions;
ppAwait = xallocarray(numwaits, sizeof(SyncAwait *));
ppAwait = calloc(numwaits, sizeof(SyncAwait *));
if (!ppAwait)
goto bail;
@ -1547,7 +1547,7 @@ SyncAwaitPrologue(ClientPtr client, int items)
/* all the memory for the entire await list is allocated
* here in one chunk
*/
pAwaitUnion = xallocarray(items + 1, sizeof(SyncAwaitUnion));
pAwaitUnion = calloc(items + 1, sizeof(SyncAwaitUnion));
if (!pAwaitUnion)
return NULL;

View File

@ -1198,11 +1198,11 @@ ProcVidModeGetMonitor(ClientPtr client)
pad_to_int32(rep.modelLength));
rep.nhsync = nHsync;
rep.nvsync = nVrefresh;
hsyncdata = xallocarray(nHsync, sizeof(CARD32));
hsyncdata = calloc(nHsync, sizeof(CARD32));
if (!hsyncdata) {
return BadAlloc;
}
vsyncdata = xallocarray(nVrefresh, sizeof(CARD32));
vsyncdata = calloc(nVrefresh, sizeof(CARD32));
if (!vsyncdata) {
free(hsyncdata);
@ -1520,7 +1520,7 @@ ProcVidModeGetGammaRamp(ClientPtr client)
length = (stuff->size + 1) & ~1;
if (stuff->size) {
if (!(ramp = xallocarray(length, 3 * sizeof(CARD16))))
if (!(ramp = calloc(length, 3 * sizeof(CARD16))))
return BadAlloc;
ramplen = length * 3 * sizeof(CARD16);

View File

@ -99,7 +99,7 @@ ProcXCMiscGetXIDList(ClientPtr client)
if (stuff->count > UINT32_MAX / sizeof(XID))
return BadAlloc;
pids = xallocarray(stuff->count, sizeof(XID));
pids = calloc(stuff->count, sizeof(XID));
if (!pids) {
return BadAlloc;
}

View File

@ -390,7 +390,7 @@ ProcXF86BigfontQueryFont(ClientPtr client)
}
else {
#endif
pCI = xallocarray(nCharInfos, sizeof(xCharInfo));
pCI = calloc(nCharInfos, sizeof(xCharInfo));
if (!pCI)
return BadAlloc;
#ifdef MITSHM
@ -452,7 +452,7 @@ ProcXF86BigfontQueryFont(ClientPtr client)
if (hashModulus > nCharInfos + 1)
hashModulus = nCharInfos + 1;
tmp = xallocarray(4 * nCharInfos + 1, sizeof(CARD16));
tmp = calloc(4 * nCharInfos + 1, sizeof(CARD16));
if (!tmp) {
if (!pDesc)
free(pCI);

View File

@ -220,12 +220,13 @@ ProcXResQueryClients(ClientPtr client)
{
/* REQUEST(xXResQueryClientsReq); */
xXResQueryClientsReply rep;
int *current_clients;
int i, num_clients;
REQUEST_SIZE_MATCH(xXResQueryClientsReq);
current_clients = xallocarray(currentMaxClients, sizeof(int));
int *current_clients = calloc(currentMaxClients, sizeof(int));
if (!current_clients)
return BadAlloc;
num_clients = 0;
for (i = 0; i < currentMaxClients; i++) {
@ -300,7 +301,6 @@ ProcXResQueryClientResources(ClientPtr client)
REQUEST(xXResQueryClientResourcesReq);
xXResQueryClientResourcesReply rep;
int i, clientID, num_types;
int *counts;
REQUEST_SIZE_MATCH(xXResQueryClientResourcesReq);
@ -311,7 +311,9 @@ ProcXResQueryClientResources(ClientPtr client)
return BadValue;
}
counts = calloc(lastResourceType + 1, sizeof(int));
int *counts = calloc(lastResourceType + 1, sizeof(int));
if (!counts)
return BadAlloc;
FindAllClientResources(clients[clientID], ResFindAllRes, counts);

View File

@ -1083,7 +1083,7 @@ XvFillColorKey(DrawablePtr pDraw, CARD32 key, RegionPtr region)
(void) ChangeGC(NullClient, gc, GCForeground | GCSubwindowMode, pval);
ValidateGC(pDraw, gc);
rects = xallocarray(nbox, sizeof(xRectangle));
rects = calloc(nbox, sizeof(xRectangle));
if (rects) {
for (i = 0; i < nbox; i++, pbox++) {
rects[i].x = pbox->x1 - pDraw->x;

View File

@ -117,7 +117,9 @@ ProcXGetDeviceDontPropagateList(ClientPtr client)
ClassFromMask(NULL, others->dontPropagateMask[i], i, &count, COUNT);
if (count) {
rep.count = count;
buf = xallocarray(rep.count, sizeof(XEventClass));
buf = calloc(rep.count, sizeof(XEventClass));
if (!buf)
return BadAlloc;
rep.length = bytes_to_int32(rep.count * sizeof(XEventClass));
tbuf = buf;

View File

@ -221,7 +221,7 @@ list_atoms(DeviceIntPtr dev, int *natoms, Atom **atoms_return)
if (nprops) {
Atom *a;
atoms = xallocarray(nprops, sizeof(Atom));
atoms = calloc(nprops, sizeof(Atom));
if (!atoms)
return BadAlloc;
a = atoms;
@ -724,7 +724,7 @@ XIChangeDeviceProperty(DeviceIntPtr dev, Atom property, Atom type,
if (mode == PropModeReplace || len > 0) {
void *new_data = NULL, *old_data = NULL;
new_value.data = xallocarray(total_len, size_in_bytes);
new_value.data = calloc(total_len, size_in_bytes);
if (!new_value.data && total_len && size_in_bytes) {
if (add)
XIDestroyDeviceProperty(prop);

View File

@ -470,7 +470,7 @@ ProcDbeSwapBuffers(ClientPtr client)
dbeSwapInfo = (xDbeSwapInfo *) &stuff[1];
/* Allocate array to record swap information. */
swapInfo = xallocarray(nStuff, sizeof(DbeSwapInfoRec));
swapInfo = calloc(nStuff, sizeof(DbeSwapInfoRec));
if (swapInfo == NULL) {
return BadAlloc;
}
@ -583,7 +583,7 @@ ProcDbeGetVisualInfo(ClientPtr client)
return BadAlloc;
/* Make sure any specified drawables are valid. */
if (stuff->n != 0) {
if (!(pDrawables = xallocarray(stuff->n, sizeof(DrawablePtr)))) {
if (!(pDrawables = calloc(stuff->n, sizeof(DrawablePtr)))) {
return BadAlloc;
}

View File

@ -85,7 +85,7 @@ miDbeGetVisualInfo(ScreenPtr pScreen, XdbeScreenVisualInfo * pScrVisInfo)
}
/* Allocate an array of XdbeVisualInfo items. */
if (!(visInfo = xallocarray(count, sizeof(XdbeVisualInfo)))) {
if (!(visInfo = calloc(count, sizeof(XdbeVisualInfo)))) {
return FALSE; /* memory alloc failure */
}

View File

@ -199,7 +199,7 @@ InitAtoms(void)
{
FreeAllAtoms();
tableLength = InitialTableSize;
nodeTable = xallocarray(InitialTableSize, sizeof(NodePtr));
nodeTable = calloc(InitialTableSize, sizeof(NodePtr));
if (!nodeTable)
AtomError();
nodeTable[None] = NULL;

View File

@ -308,7 +308,7 @@ CreateColormap(Colormap mid, ScreenPtr pScreen, VisualPtr pVisual,
for (pent = &pmap->red[size - 1]; pent >= pmap->red; pent--)
pent->refcnt = AllocPrivate;
pmap->freeRed = 0;
ppix = xallocarray(size, sizeof(Pixel));
ppix = calloc(size, sizeof(Pixel));
if (!ppix) {
free(pmap);
return BadAlloc;
@ -349,7 +349,7 @@ CreateColormap(Colormap mid, ScreenPtr pScreen, VisualPtr pVisual,
for (pent = &pmap->green[size - 1]; pent >= pmap->green; pent--)
pent->refcnt = AllocPrivate;
pmap->freeGreen = 0;
ppix = xallocarray(size, sizeof(Pixel));
ppix = calloc(size, sizeof(Pixel));
if (!ppix) {
free(pmap->clientPixelsRed[client]);
free(pmap);
@ -364,7 +364,7 @@ CreateColormap(Colormap mid, ScreenPtr pScreen, VisualPtr pVisual,
for (pent = &pmap->blue[size - 1]; pent >= pmap->blue; pent--)
pent->refcnt = AllocPrivate;
pmap->freeBlue = 0;
ppix = xallocarray(size, sizeof(Pixel));
ppix = calloc(size, sizeof(Pixel));
if (!ppix) {
free(pmap->clientPixelsGreen[client]);
free(pmap->clientPixelsRed[client]);
@ -714,7 +714,7 @@ doUpdateColors(ColormapPtr pmap)
pVisual = pmap->pVisual;
size = pVisual->ColormapEntries;
defs = xallocarray(size, sizeof(xColorItem));
defs = calloc(size, sizeof(xColorItem));
if (!defs)
return;
n = 0;
@ -1660,9 +1660,9 @@ AllocDirect(int client, ColormapPtr pmap, int c, int r, int g, int b,
for (p = pixels; p < pixels + c; p++)
*p = 0;
ppixRed = xallocarray(npixR, sizeof(Pixel));
ppixGreen = xallocarray(npixG, sizeof(Pixel));
ppixBlue = xallocarray(npixB, sizeof(Pixel));
ppixRed = calloc(npixR, sizeof(Pixel));
ppixGreen = calloc(npixG, sizeof(Pixel));
ppixBlue = calloc(npixB, sizeof(Pixel));
if (!ppixRed || !ppixGreen || !ppixBlue) {
free(ppixBlue);
free(ppixGreen);
@ -1760,7 +1760,7 @@ AllocPseudo(int client, ColormapPtr pmap, int c, int r, Bool contig,
npix = c << r;
if ((r >= 32) || (npix > pmap->freeRed) || (npix < c))
return BadAlloc;
if (!(ppixTemp = xallocarray(npix, sizeof(Pixel))))
if (!(ppixTemp = calloc(npix, sizeof(Pixel))))
return BadAlloc;
ok = AllocCP(pmap, pmap->red, c, r, contig, ppixTemp, pmask);
@ -1972,7 +1972,7 @@ AllocShared(ColormapPtr pmap, Pixel * ppix, int c, int r, int g, int b,
npixClientNew = c << (r + g + b);
npixShared = (c << r) + (c << g) + (c << b);
psharedList = xallocarray(npixShared, sizeof(SHAREDCOLOR *));
psharedList = calloc(npixShared, sizeof(SHAREDCOLOR *));
if (!psharedList)
return FALSE;
ppshared = psharedList;
@ -2481,7 +2481,7 @@ IsMapInstalled(Colormap map, WindowPtr pWin)
Colormap *pmaps;
int imap, nummaps, found;
pmaps = xallocarray(pWin->drawable.pScreen->maxInstalledCmaps,
pmaps = calloc(pWin->drawable.pScreen->maxInstalledCmaps,
sizeof(Colormap));
if (!pmaps)
return FALSE;

View File

@ -285,6 +285,10 @@ AddInputDevice(ClientPtr client, DeviceProc deviceProc, Bool autoStart)
dev->deviceGrab.ActivateGrab = ActivateKeyboardGrab;
dev->deviceGrab.DeactivateGrab = DeactivateKeyboardGrab;
dev->deviceGrab.sync.event = calloc(1, sizeof(InternalEvent));
if (!(dev->deviceGrab.sync.event)) {
free(dev);
return NULL;
}
dev->sendEventsProc = XTestDeviceSendEvents;
@ -1554,8 +1558,8 @@ InitStringFeedbackClassDeviceStruct(DeviceIntPtr dev,
feedc->ctrl.num_symbols_displayed = 0;
feedc->ctrl.max_symbols = max_symbols;
feedc->ctrl.symbols_supported =
xallocarray(num_symbols_supported, sizeof(KeySym));
feedc->ctrl.symbols_displayed = xallocarray(max_symbols, sizeof(KeySym));
calloc(num_symbols_supported, sizeof(KeySym));
feedc->ctrl.symbols_displayed = calloc(max_symbols, sizeof(KeySym));
if (!feedc->ctrl.symbols_supported || !feedc->ctrl.symbols_displayed) {
free(feedc->ctrl.symbols_supported);
free(feedc->ctrl.symbols_displayed);
@ -1704,6 +1708,8 @@ InitTouchClassDeviceStruct(DeviceIntPtr device, unsigned int max_touches,
device->touch = touch;
device->last.touches = calloc(max_touches, sizeof(*device->last.touches));
if (!(device->last.touches))
goto err;
device->last.num_touches = touch->num_touches;
for (i = 0; i < touch->num_touches; i++)
TouchInitDDXTouchPoint(device, &device->last.touches[i]);
@ -2800,8 +2806,8 @@ AllocDevicePair(ClientPtr client, const char *name,
DeviceIntPtr *keybd,
DeviceProc ptr_proc, DeviceProc keybd_proc, Bool master)
{
DeviceIntPtr pointer;
DeviceIntPtr keyboard;
DeviceIntPtr pointer = NULL;
DeviceIntPtr keyboard = NULL;
char *dev_name;
*ptr = *keybd = NULL;
@ -2809,15 +2815,12 @@ AllocDevicePair(ClientPtr client, const char *name,
XkbInitPrivates();
pointer = AddInputDevice(client, ptr_proc, TRUE);
if (!pointer)
return BadAlloc;
goto badalloc;
if (asprintf(&dev_name, "%s pointer", name) == -1) {
RemoveDevice(pointer, FALSE);
if (asprintf(&dev_name, "%s pointer", name) == -1)
goto badalloc;
return BadAlloc;
}
pointer->name = dev_name;
pointer->public.processInputProc = ProcessOtherEvent;
@ -2833,18 +2836,12 @@ AllocDevicePair(ClientPtr client, const char *name,
pointer->type = (master) ? MASTER_POINTER : SLAVE;
keyboard = AddInputDevice(client, keybd_proc, TRUE);
if (!keyboard) {
RemoveDevice(pointer, FALSE);
if (!keyboard)
goto badalloc;
return BadAlloc;
}
if (asprintf(&dev_name, "%s keyboard", name) == -1)
goto badalloc;
if (asprintf(&dev_name, "%s keyboard", name) == -1) {
RemoveDevice(keyboard, FALSE);
RemoveDevice(pointer, FALSE);
return BadAlloc;
}
keyboard->name = dev_name;
keyboard->public.processInputProc = ProcessOtherEvent;
@ -2863,6 +2860,8 @@ AllocDevicePair(ClientPtr client, const char *name,
if (IsMaster(pointer)) {
pointer->unused_classes = calloc(1, sizeof(ClassesRec));
keyboard->unused_classes = calloc(1, sizeof(ClassesRec));
if (!pointer->unused_classes || !keyboard->unused_classes)
goto badalloc;
}
*ptr = pointer;
@ -2870,6 +2869,12 @@ AllocDevicePair(ClientPtr client, const char *name,
*keybd = keyboard;
return Success;
badalloc:
// safe to call them even with NULL pointer
RemoveDevice(keyboard, FALSE);
RemoveDevice(pointer, FALSE);
return BadAlloc;
}
/**

View File

@ -1089,7 +1089,7 @@ ProcQueryTree(ClientPtr client)
if (numChildren) {
int curChild = 0;
childIDs = xallocarray(numChildren, sizeof(Window));
childIDs = calloc(numChildren, sizeof(Window));
if (!childIDs)
return BadAlloc;
for (pChild = pWin->lastChild; pChild != pHead;

View File

@ -426,7 +426,7 @@ OpenFont(ClientPtr client, XID fid, Mask flags, unsigned lenfname,
* copy the current FPE list, so that if it gets changed by another client
* while we're blocking, the request still appears atomic
*/
c->fpe_list = xallocarray(num_fpes, sizeof(FontPathElementPtr));
c->fpe_list = calloc(num_fpes, sizeof(FontPathElementPtr));
if (!c->fpe_list) {
free((void *) c->fontname);
free(c);
@ -816,7 +816,7 @@ ListFonts(ClientPtr client, unsigned char *pattern, unsigned length,
if (!(c = malloc(sizeof *c)))
return BadAlloc;
c->fpe_list = xallocarray(num_fpes, sizeof(FontPathElementPtr));
c->fpe_list = calloc(num_fpes, sizeof(FontPathElementPtr));
if (!c->fpe_list) {
free(c);
return BadAlloc;
@ -1062,7 +1062,7 @@ StartListFontsWithInfo(ClientPtr client, int length, unsigned char *pattern,
if (!(c = malloc(sizeof *c)))
goto badAlloc;
c->fpe_list = xallocarray(num_fpes, sizeof(FontPathElementPtr));
c->fpe_list = calloc(num_fpes, sizeof(FontPathElementPtr));
if (!c->fpe_list) {
free(c);
goto badAlloc;
@ -1428,7 +1428,7 @@ doImageText(ClientPtr client, ITclosurePtr c)
*new_closure = *c;
c = new_closure;
data = xallocarray(c->nChars, itemSize);
data = calloc(c->nChars, itemSize);
if (!data) {
free(c);
c = old_closure;
@ -1581,7 +1581,7 @@ SetFontPathElements(int npaths, unsigned char *paths, int *bad, Bool persist)
unsigned char *cp = paths;
FontPathElementPtr fpe = NULL, *fplist;
fplist = xallocarray(npaths, sizeof(FontPathElementPtr));
fplist = calloc(npaths, sizeof(FontPathElementPtr));
if (!fplist) {
*bad = 0;
return BadAlloc;

View File

@ -599,10 +599,10 @@ DeletePassiveGrabFromList(GrabPtr pMinuendGrab)
i++;
if (!i)
return TRUE;
deletes = xallocarray(i, sizeof(GrabPtr));
adds = xallocarray(i, sizeof(GrabPtr));
updates = xallocarray(i, sizeof(Mask **));
details = xallocarray(i, sizeof(Mask *));
deletes = calloc(i, sizeof(GrabPtr));
adds = calloc(i, sizeof(GrabPtr));
updates = calloc(i, sizeof(Mask **));
details = calloc(i, sizeof(Mask *));
if (!deletes || !adds || !updates || !details) {
free(details);
free(updates);

View File

@ -149,8 +149,8 @@ ProcRotateProperties(ClientPtr client)
return rc;
atoms = (Atom *) &stuff[1];
props = xallocarray(stuff->nAtoms, sizeof(PropertyPtr));
saved = xallocarray(stuff->nAtoms, sizeof(PropertyRec));
props = calloc(stuff->nAtoms, sizeof(PropertyPtr));
saved = calloc(stuff->nAtoms, sizeof(PropertyRec));
if (!props || !saved) {
rc = BadAlloc;
goto out;
@ -331,7 +331,7 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property,
/* do nothing */
}
else if (mode == PropModeAppend) {
data = xallocarray(pProp->size + len, sizeInBytes);
data = calloc(pProp->size + len, sizeInBytes);
if (!data)
return BadAlloc;
memcpy(data, pProp->data, pProp->size * sizeInBytes);
@ -340,7 +340,7 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property,
pProp->size += len;
}
else if (mode == PropModePrepend) {
data = xallocarray(len + pProp->size, sizeInBytes);
data = calloc(len + pProp->size, sizeInBytes);
if (!data)
return BadAlloc;
memcpy(data + totalSize, pProp->data, pProp->size * sizeInBytes);
@ -592,7 +592,7 @@ ProcListProperties(ClientPtr client)
numProps++;
if (numProps) {
pAtoms = xallocarray(numProps, sizeof(Atom));
pAtoms = calloc(numProps, sizeof(Atom));
if (!pAtoms)
return BadAlloc;

View File

@ -852,10 +852,10 @@ RebuildTable(int client)
*/
j = 2 * clientTable[client].buckets;
tails = xallocarray(j, sizeof(ResourcePtr *));
tails = calloc(j, sizeof(ResourcePtr *));
if (!tails)
return;
resources = xallocarray(j, sizeof(ResourcePtr));
resources = calloc(j, sizeof(ResourcePtr));
if (!resources) {
free(tails);
return;

View File

@ -371,7 +371,6 @@ exaHWCopyNtoN(DrawablePtr pSrcDrawable,
int src_off_x, src_off_y;
int dst_off_x, dst_off_y;
RegionPtr srcregion = NULL, dstregion = NULL;
xRectangle *rects;
Bool ret = TRUE;
/* avoid doing copy operations if no boxes */
@ -384,8 +383,7 @@ exaHWCopyNtoN(DrawablePtr pSrcDrawable,
exaGetDrawableDeltas(pSrcDrawable, pSrcPixmap, &src_off_x, &src_off_y);
exaGetDrawableDeltas(pDstDrawable, pDstPixmap, &dst_off_x, &dst_off_y);
rects = xallocarray(nbox, sizeof(xRectangle));
xRectangle *rects = calloc(nbox, sizeof(xRectangle));
if (rects) {
int i;
int ordering;
@ -614,7 +612,6 @@ exaPolyPoint(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt,
{
ExaScreenPriv(pDrawable->pScreen);
int i;
xRectangle *prect;
/* If we can't reuse the current GC as is, don't bother accelerating the
* points.
@ -624,7 +621,9 @@ exaPolyPoint(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt,
return;
}
prect = xallocarray(npt, sizeof(xRectangle));
xRectangle *prect = calloc(npt, sizeof(xRectangle));
if (!prect)
return;
for (i = 0; i < npt; i++) {
prect[i].x = ppt[i].x;
prect[i].y = ppt[i].y;
@ -649,7 +648,6 @@ exaPolylines(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt,
DDXPointPtr ppt)
{
ExaScreenPriv(pDrawable->pScreen);
xRectangle *prect;
int x1, x2, y1, y2;
int i;
@ -665,7 +663,9 @@ exaPolylines(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt,
return;
}
prect = xallocarray(npt - 1, sizeof(xRectangle));
xRectangle *prect = calloc(npt - 1, sizeof(xRectangle));
if (!prect)
return;
x1 = ppt[0].x;
y1 = ppt[0].y;
/* If we have any non-horizontal/vertical, fall back. */
@ -718,7 +718,6 @@ static void
exaPolySegment(DrawablePtr pDrawable, GCPtr pGC, int nseg, xSegment * pSeg)
{
ExaScreenPriv(pDrawable->pScreen);
xRectangle *prect;
int i;
/* Don't try to do wide lines or non-solid fill style. */
@ -736,7 +735,9 @@ exaPolySegment(DrawablePtr pDrawable, GCPtr pGC, int nseg, xSegment * pSeg)
}
}
prect = xallocarray((unsigned int)nseg, sizeof(xRectangle));
xRectangle *prect = calloc((unsigned int)nseg, sizeof(xRectangle));
if (!prect)
return;
for (i = 0; i < nseg; i++) {
if (pSeg[i].x1 < pSeg[i].x2) {
prect[i].x = pSeg[i].x1;

View File

@ -209,8 +209,8 @@ exaRealizeGlyphCaches(ScreenPtr pScreen, unsigned int format)
cache->picture = pPicture;
cache->picture->refcnt++;
cache->hashEntries = xallocarray(cache->hashSize, sizeof(int));
cache->glyphs = xallocarray(cache->size, sizeof(ExaCachedGlyphRec));
cache->hashEntries = calloc(cache->hashSize, sizeof(int));
cache->glyphs = calloc(cache->size, sizeof(ExaCachedGlyphRec));
cache->glyphCount = 0;
if (!cache->hashEntries || !cache->glyphs)

View File

@ -203,7 +203,7 @@ exaPrepareAccessReg_mixed(PixmapPtr pPixmap, int index, RegionPtr pReg)
/* Do we need to allocate our system buffer? */
if (!pExaPixmap->sys_ptr) {
pExaPixmap->sys_ptr = xallocarray(pExaPixmap->sys_pitch,
pExaPixmap->sys_ptr = calloc(pExaPixmap->sys_pitch,
pPixmap->drawable.height);
if (!pExaPixmap->sys_ptr)
FatalError("EXA: malloc failed for size %d bytes\n",

View File

@ -192,7 +192,7 @@ fbCopyNto1(DrawablePtr pSrcDrawable,
height = pbox->y2 - pbox->y1;
tmpStride = ((width + FB_STIP_MASK) >> FB_STIP_SHIFT);
tmp = xallocarray(tmpStride * height, sizeof(FbStip));
tmp = calloc(tmpStride * height, sizeof(FbStip));
if (!tmp)
return;

View File

@ -122,7 +122,7 @@ fbGlyphs(CARD8 op,
pixman_glyph_cache_freeze (glyphCache);
if (n_glyphs > N_STACK_GLYPHS) {
if (!(pglyphs = xallocarray(n_glyphs, sizeof(pixman_glyph_t))))
if (!(pglyphs = calloc(n_glyphs, sizeof(pixman_glyph_t))))
goto out;
}

View File

@ -57,7 +57,7 @@ _pixman_region_init_clipped_rectangles(pixman_region16_t * region,
unsigned int i, j;
if (num_rects > ARRAY_SIZE(stack_boxes)) {
boxes = xallocarray(num_rects, sizeof(pixman_box16_t));
boxes = calloc(num_rects, sizeof(pixman_box16_t));
if (boxes == NULL)
return FALSE;
}

View File

@ -989,13 +989,13 @@ glamor_generate_radial_gradient_picture(ScreenPtr screen,
/* Set all the stops and colors to shader. */
if (stops_count > RADIAL_SMALL_STOPS) {
stop_colors = xallocarray(stops_count, 4 * sizeof(float));
stop_colors = calloc(stops_count, 4 * sizeof(float));
if (stop_colors == NULL) {
ErrorF("Failed to allocate stop_colors memory.\n");
goto GRADIENT_FAIL;
}
n_stops = xallocarray(stops_count, sizeof(float));
n_stops = calloc(stops_count, sizeof(float));
if (n_stops == NULL) {
ErrorF("Failed to allocate n_stops memory.\n");
goto GRADIENT_FAIL;
@ -1327,13 +1327,13 @@ glamor_generate_linear_gradient_picture(ScreenPtr screen,
/* Set all the stops and colors to shader. */
if (stops_count > LINEAR_SMALL_STOPS) {
stop_colors = xallocarray(stops_count, 4 * sizeof(float));
stop_colors = calloc(stops_count, 4 * sizeof(float));
if (stop_colors == NULL) {
ErrorF("Failed to allocate stop_colors memory.\n");
goto GRADIENT_FAIL;
}
n_stops = xallocarray(stops_count, sizeof(float));
n_stops = calloc(stops_count, sizeof(float));
if (n_stops == NULL) {
ErrorF("Failed to allocate n_stops memory.\n");
goto GRADIENT_FAIL;

View File

@ -118,7 +118,7 @@ glamor_prep_drawable_box(DrawablePtr drawable, glamor_access_t access, BoxPtr bo
}
if (!priv->pbo) {
pixmap->devPrivate.ptr = xallocarray(pixmap->devKind,
pixmap->devPrivate.ptr = calloc(pixmap->devKind,
pixmap->drawable.height);
if (!pixmap->devPrivate.ptr)
return FALSE;

View File

@ -30,7 +30,7 @@ glamor_solid_boxes(DrawablePtr drawable,
xRectangle *rect;
int n;
rect = xallocarray(nbox, sizeof(xRectangle));
rect = calloc(nbox, sizeof(xRectangle));
if (!rect)
return;
for (n = 0; n < nbox; n++) {

View File

@ -931,7 +931,7 @@ hostx_screen_init(KdScreenInfo *screen,
scrpriv->ximg->byte_order = IMAGE_BYTE_ORDER;
scrpriv->ximg->data =
xallocarray(scrpriv->ximg->stride, buffer_height);
calloc(scrpriv->ximg->stride, buffer_height);
}
if (!HostX.size_set_from_configure)
@ -1000,7 +1000,7 @@ hostx_screen_init(KdScreenInfo *screen,
*bits_per_pixel = scrpriv->server_depth;
EPHYR_DBG("server bpp %i", bytes_per_pixel);
scrpriv->fb_data = xallocarray (stride, buffer_height);
scrpriv->fb_data = calloc(stride, buffer_height);
return scrpriv->fb_data;
}
}

View File

@ -34,7 +34,7 @@ KdShadowFbAlloc(KdScreenInfo * screen, Bool rotate)
/* use fb computation for width */
paddedWidth = ((width * bpp + FB_MASK) >> FB_SHIFT) * sizeof(FbBits);
buf = xallocarray(paddedWidth, height);
buf = calloc(paddedWidth, height);
if (!buf)
return FALSE;
if (screen->fb.shadow)

View File

@ -483,9 +483,11 @@ vfbInstallColormap(ColormapPtr pmap)
swapcopy32(pXWDHeader->bits_per_rgb, pVisual->bitsPerRGBValue);
swapcopy32(pXWDHeader->colormap_entries, pVisual->ColormapEntries);
ppix = xallocarray(entries, sizeof(Pixel));
prgb = xallocarray(entries, sizeof(xrgb));
defs = xallocarray(entries, sizeof(xColorItem));
ppix = calloc(entries, sizeof(Pixel));
prgb = calloc(entries, sizeof(xrgb));
defs = calloc(entries, sizeof(xColorItem));
if (!ppix || !prgb || !defs)
goto out;
for (i = 0; i < entries; i++)
ppix[i] = i;
@ -501,6 +503,7 @@ vfbInstallColormap(ColormapPtr pmap)
}
(*pmap->pScreen->StoreColors) (pmap, entries, defs);
out:
free(ppix);
free(prgb);
free(defs);

View File

@ -1322,7 +1322,7 @@ ProcXDGAQueryModes(ClientPtr client)
return Success;
}
if (!(mode = xallocarray(num, sizeof(XDGAModeRec))))
if (!(mode = calloc(num, sizeof(XDGAModeRec))))
return BadAlloc;
for (i = 0; i < num; i++)

View File

@ -160,10 +160,10 @@ xf86HandleColormaps(ScreenPtr pScreen,
elements = 1 << sigRGBbits;
if (!(gamma = xallocarray(elements, sizeof(LOCO))))
if (!(gamma = calloc(elements, sizeof(LOCO))))
return FALSE;
if (!(indices = xallocarray(maxColors, sizeof(int)))) {
if (!(indices = calloc(maxColors, sizeof(int)))) {
free(gamma);
return FALSE;
}
@ -273,7 +273,7 @@ CMapAllocateColormapPrivate(ColormapPtr pmap)
else
numColors = 1 << pmap->pVisual->nplanes;
if (!(colors = xallocarray(numColors, sizeof(LOCO))))
if (!(colors = calloc(numColors, sizeof(LOCO))))
return FALSE;
if (!(pColPriv = malloc(sizeof(CMapColormapRec)))) {

View File

@ -648,7 +648,7 @@ xf86SbusCmapLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
return;
fbcmap.count = 0;
fbcmap.index = indices[0];
fbcmap.red = data = xallocarray(numColors, 3);
fbcmap.red = data = calloc(numColors, 3);
if (!data)
return;
fbcmap.green = data + numColors;

View File

@ -155,7 +155,7 @@ xf86XvMCScreenInit(ScreenPtr pScreen,
if (noXvExtension)
return FALSE;
if (!(pAdapt = xallocarray(num_adaptors, sizeof(XvMCAdaptorRec))))
if (!(pAdapt = calloc(num_adaptors, sizeof(XvMCAdaptorRec))))
return FALSE;
if (!dixRegisterPrivateKey(&XF86XvMCScreenKeyRec, PRIVATE_SCREEN, 0)) {

View File

@ -423,7 +423,7 @@ ProcXF86DRIGetDrawableInfo(register ClientPtr client)
if (rep.numClipRects) {
/* Clip cliprects to screen dimensions (redirected windows) */
pClippedRects = xallocarray(rep.numClipRects, sizeof(drm_clip_rect_t));
pClippedRects = calloc(rep.numClipRects, sizeof(drm_clip_rect_t));
if (!pClippedRects)
return BadAlloc;

View File

@ -1608,7 +1608,7 @@ DRI2ScreenInit(ScreenPtr pScreen, DRI2InfoPtr info)
if (info->version == 3 || info->numDrivers == 0) {
/* Driver too old: use the old-style driverName field */
ds->numDrivers = info->driverName ? 1 : 2;
ds->driverNames = xallocarray(ds->numDrivers, sizeof(*ds->driverNames));
ds->driverNames = calloc(ds->numDrivers, sizeof(*ds->driverNames));
if (!ds->driverNames)
goto err_out;
@ -1629,7 +1629,7 @@ DRI2ScreenInit(ScreenPtr pScreen, DRI2InfoPtr info)
}
else {
ds->numDrivers = info->numDrivers;
ds->driverNames = xallocarray(info->numDrivers, sizeof(*ds->driverNames));
ds->driverNames = calloc(info->numDrivers, sizeof(*ds->driverNames));
if (!ds->driverNames)
goto err_out;
memcpy(ds->driverNames, info->driverNames,

View File

@ -588,7 +588,7 @@ dispatch_damages(ScrnInfoPtr scrn, xf86CrtcPtr crtc, RegionPtr dirty,
return 0;
if (num_cliprects) {
drmModeClip *clip = xallocarray(num_cliprects, sizeof(drmModeClip));
drmModeClip *clip = calloc(num_cliprects, sizeof(drmModeClip));
BoxPtr rect = REGION_RECTS(dirty);
int i;
int c = 0;

View File

@ -3799,7 +3799,7 @@ drmmode_create_lease(RRLeasePtr lease, int *fd)
if (!lease_private)
return BadAlloc;
objects = xallocarray(nobjects, sizeof (uint32_t));
objects = calloc(nobjects, sizeof(uint32_t));
if (!objects) {
free(lease_private);

View File

@ -375,6 +375,8 @@ VBEGetVBEInfo(vbeInfoPtr pVbe)
return NULL;
block = calloc(1, sizeof(VbeInfoBlock));
if (!block)
return NULL;
block->VESASignature[0] = ((char *) pVbe->memory)[0];
block->VESASignature[1] = ((char *) pVbe->memory)[1];
block->VESASignature[2] = ((char *) pVbe->memory)[2];
@ -397,7 +399,11 @@ VBEGetVBEInfo(vbeInfoPtr pVbe)
i = 0;
while (modes[i] != 0xffff)
i++;
block->VideoModePtr = xallocarray(i + 1, sizeof(CARD16));
block->VideoModePtr = calloc(i + 1, sizeof(CARD16));
if (!(block->VideoModePtr)) {
free(block);
return NULL;
}
memcpy(block->VideoModePtr, modes, sizeof(CARD16) * i);
block->VideoModePtr[i] = 0xffff;
@ -825,7 +831,9 @@ VBESetGetPaletteData(vbeInfoPtr pVbe, Bool set, int first, int num,
if (set)
return data;
data = xallocarray(num, sizeof(CARD32));
data = calloc(num, sizeof(CARD32));
if (!data)
return NULL;
memcpy(data, pVbe->memory, num * sizeof(CARD32));
return data;

View File

@ -228,7 +228,7 @@ InitPatterns(const char **patternlist)
for (i = 0, s = patternlist; *s; i++, s++)
if (*s == DEFAULT_LIST)
i += ARRAY_SIZE(stdPatterns) - 1 - 1;
patterns = xallocarray(i + 1, sizeof(PatternRec));
patterns = calloc(i + 1, sizeof(PatternRec));
if (!patterns) {
return NULL;
}

View File

@ -114,7 +114,7 @@ xf86CrtcCreate(ScrnInfoPtr scrn, const xf86CrtcFuncsRec * funcs)
/* Preallocate gamma at a sensible size. */
crtc->gamma_size = 256;
crtc->gamma_red = xallocarray(crtc->gamma_size, 3 * sizeof(CARD16));
crtc->gamma_red = calloc(crtc->gamma_size, 3 * sizeof(CARD16));
if (!crtc->gamma_red) {
free(crtc);
return NULL;
@ -126,7 +126,7 @@ xf86CrtcCreate(ScrnInfoPtr scrn, const xf86CrtcFuncsRec * funcs)
crtcs = reallocarray(xf86_config->crtc,
xf86_config->num_crtc + 1, sizeof(xf86CrtcPtr));
else
crtcs = xallocarray(xf86_config->num_crtc + 1, sizeof(xf86CrtcPtr));
crtcs = calloc(xf86_config->num_crtc + 1, sizeof(xf86CrtcPtr));
if (!crtcs) {
free(crtc->gamma_red);
free(crtc);
@ -670,8 +670,7 @@ xf86OutputCreate(ScrnInfoPtr scrn,
xf86_config->num_output + 1,
sizeof(xf86OutputPtr));
else
outputs = xallocarray(xf86_config->num_output + 1,
sizeof(xf86OutputPtr));
outputs = calloc(xf86_config->num_output + 1, sizeof(xf86OutputPtr));
if (!outputs) {
free(output);
return NULL;
@ -992,7 +991,7 @@ xf86PickCrtcs(ScrnInfoPtr scrn,
if (modes[n] == NULL)
return best_score;
crtcs = xallocarray(config->num_output, sizeof(xf86CrtcPtr));
crtcs = calloc(config->num_output, sizeof(xf86CrtcPtr));
if (!crtcs)
return best_score;

View File

@ -57,7 +57,7 @@ xf86_dga_get_modes(ScreenPtr pScreen)
if (!num)
return FALSE;
modes = xallocarray(num, sizeof(DGAModeRec));
modes = calloc(num, sizeof(DGAModeRec));
if (!modes)
return FALSE;

View File

@ -1061,7 +1061,7 @@ xf86RandR12CrtcNotify(RRCrtcPtr randr_crtc)
DisplayModePtr mode = &crtc->mode;
Bool ret;
randr_outputs = xallocarray(config->num_output, sizeof(RROutputPtr));
randr_outputs = calloc(config->num_output, sizeof(RROutputPtr));
if (!randr_outputs)
return FALSE;
x = crtc->x;
@ -1153,7 +1153,9 @@ xf86RandR12CrtcSet(ScreenPtr pScreen,
if (!crtc->scrn->vtSema)
return FALSE;
save_crtcs = xallocarray(config->num_output, sizeof(xf86CrtcPtr));
save_crtcs = calloc(config->num_output, sizeof(xf86CrtcPtr));
if (!save_crtcs)
return FALSE;
if ((randr_mode != NULL) != crtc->enabled)
changed = TRUE;
else if (randr_mode && !xf86RandRModeMatches(randr_mode, &crtc->mode))
@ -1429,7 +1431,7 @@ xf86RandR12CrtcInitGamma(xf86CrtcPtr crtc, float gamma_red, float gamma_green,
(gamma_red != 1.0f || gamma_green != 1.0f || gamma_blue != 1.0f))
return FALSE;
red = xallocarray(size, 3 * sizeof(CARD16));
red = calloc(size, 3 * sizeof(CARD16));
if (!red)
return FALSE;
@ -1596,7 +1598,7 @@ xf86RROutputSetModes(RROutputPtr randr_output, DisplayModePtr modes)
nmode++;
if (nmode) {
rrmodes = xallocarray(nmode, sizeof(RRModePtr));
rrmodes = calloc(nmode, sizeof(RRModePtr));
if (!rrmodes)
return FALSE;
@ -1651,8 +1653,13 @@ xf86RandR12SetInfo12(ScreenPtr pScreen)
int o, c, l;
int nclone;
clones = xallocarray(config->num_output, sizeof(RROutputPtr));
crtcs = xallocarray(config->num_crtc, sizeof(RRCrtcPtr));
clones = calloc(config->num_output, sizeof(RROutputPtr));
crtcs = calloc(config->num_crtc, sizeof(RRCrtcPtr));
if (!clones || !crtcs) {
free(clones);
free(crtcs);
return FALSE;
}
for (o = 0; o < config->num_output; o++) {
xf86OutputPtr output = config->output[o];

View File

@ -63,7 +63,9 @@ xnestCreateColormap(ColormapPtr pCmap)
switch (pVisual->class) {
case StaticGray: /* read only */
colors = xallocarray(ncolors, sizeof(XColor));
colors = calloc(ncolors, sizeof(XColor));
if (!colors)
return FALSE;
for (i = 0; i < ncolors; i++)
colors[i].pixel = i;
XQueryColors(xnestDisplay, xnestColormap(pCmap), colors, ncolors);
@ -76,7 +78,9 @@ xnestCreateColormap(ColormapPtr pCmap)
break;
case StaticColor: /* read only */
colors = xallocarray(ncolors, sizeof(XColor));
colors = calloc(ncolors, sizeof(XColor));
if (!colors)
return FALSE;
for (i = 0; i < ncolors; i++)
colors[i].pixel = i;
XQueryColors(xnestDisplay, xnestColormap(pCmap), colors, ncolors);
@ -89,7 +93,9 @@ xnestCreateColormap(ColormapPtr pCmap)
break;
case TrueColor: /* read only */
colors = xallocarray(ncolors, sizeof(XColor));
colors = calloc(ncolors, sizeof(XColor));
if (!colors)
return FALSE;
red = green = blue = 0L;
redInc = lowbit(pVisual->redMask);
greenInc = lowbit(pVisual->greenMask);
@ -195,12 +201,18 @@ xnestSetInstalledColormapWindows(ScreenPtr pScreen)
xnestInstalledColormapWindows icws;
int numWindows;
icws.cmapIDs = xallocarray(pScreen->maxInstalledCmaps, sizeof(Colormap));
icws.cmapIDs = calloc(pScreen->maxInstalledCmaps, sizeof(Colormap));
if (!icws.cmapIDs)
return;
icws.numCmapIDs = xnestListInstalledColormaps(pScreen, icws.cmapIDs);
icws.numWindows = 0;
WalkTree(pScreen, xnestCountInstalledColormapWindows, (void *) &icws);
if (icws.numWindows) {
icws.windows = xallocarray(icws.numWindows + 1, sizeof(Window));
icws.windows = calloc(icws.numWindows + 1, sizeof(Window));
if (!icws.windows) {
free(icws.cmapIDs);
return;
}
icws.index = 0;
WalkTree(pScreen, xnestGetInstalledColormapWindows, (void *) &icws);
icws.windows[icws.numWindows] = xnestDefaultWindows[pScreen->myNum];
@ -219,7 +231,9 @@ xnestSetInstalledColormapWindows(ScreenPtr pScreen)
#ifdef _XSERVER64
{
int i;
Window64 *windows = xallocarray(numWindows, sizeof(Window64));
Window64 *windows = calloc(numWindows, sizeof(Window64));
if (!windows)
return;
for (i = 0; i < numWindows; ++i)
windows[i] = icws.windows[i];
@ -391,7 +405,9 @@ xnestStoreColors(ColormapPtr pCmap, int nColors, xColorItem * pColors)
#ifdef _XSERVER64
{
int i;
XColor *pColors64 = xallocarray(nColors, sizeof(XColor));
XColor *pColors64 = calloc(nColors, sizeof(XColor));
if (!pColors64)
return;
for (i = 0; i < nColors; ++i) {
pColors64[i].pixel = pColors[i].pixel;

View File

@ -117,8 +117,9 @@ xnestOpenDisplay(int argc, char *argv[])
}
xnestNumDefaultColormaps = xnestNumVisuals;
xnestDefaultColormaps = xallocarray(xnestNumDefaultColormaps,
sizeof(Colormap));
xnestDefaultColormaps = calloc(xnestNumDefaultColormaps, sizeof(Colormap));
if (!xnestDefaultColormaps)
return;
for (i = 0; i < xnestNumDefaultColormaps; i++)
xnestDefaultColormaps[i] = XCreateColormap(xnestDisplay,
DefaultRootWindow

View File

@ -203,7 +203,9 @@ xnestChangeClip(GCPtr pGC, int type, void *pValue, int nRects)
case CT_REGION:
nRects = RegionNumRects((RegionPtr) pValue);
pRects = xallocarray(nRects, sizeof(*pRects));
pRects = calloc(nRects, sizeof(*pRects));
if (!pRects)
break;
pBox = RegionRects((RegionPtr) pValue);
for (i = nRects; i-- > 0;) {
pRects[i].x = pBox[i].x1;

View File

@ -119,7 +119,8 @@ xnestKeyboardProc(DeviceIntPtr pDev, int onoff)
max_keycode - min_keycode + 1,
&mapWidth);
len = (max_keycode - min_keycode + 1) * mapWidth;
keymap = xallocarray(len, sizeof(KeySym));
if (!(keymap = calloc(len, sizeof(KeySym))))
goto XkbError;
for (i = 0; i < len; ++i)
keymap[i] = keymap64[i];
XFree(keymap64);

View File

@ -164,7 +164,9 @@ xnestOpenScreen(ScreenPtr pScreen, int argc, char *argv[])
PRIVATE_CURSOR, 0))
return FALSE;
visuals = xallocarray(xnestNumVisuals, sizeof(VisualRec));
visuals = calloc(xnestNumVisuals, sizeof(VisualRec));
if (!visuals)
return FALSE;
numVisuals = 0;
depths = (DepthPtr) malloc(MAXDEPTH * sizeof(DepthRec));

View File

@ -125,7 +125,6 @@ xwl_randr_request_lease(ClientPtr client, ScreenPtr screen, RRLeasePtr rrLease)
{
struct xwl_screen *xwl_screen;
struct wp_drm_lease_request_v1 *req;
struct xwl_drm_lease *lease_private;
struct xwl_drm_lease_device *lease_device = NULL;
struct xwl_drm_lease_device *device_data;
struct xwl_output *output;
@ -165,7 +164,9 @@ xwl_randr_request_lease(ClientPtr client, ScreenPtr screen, RRLeasePtr rrLease)
req = wp_drm_lease_device_v1_create_lease_request(
lease_device->drm_lease_device);
lease_private = calloc(1, sizeof(struct xwl_drm_lease));
struct xwl_drm_lease *lease_private = calloc(1, sizeof(struct xwl_drm_lease));
if (!lease_private)
return BadAlloc;
for (i = 0; i < rrLease->numOutputs; ++i) {
output = rrLease->outputs[i]->devPrivate;
output->lease = lease_private;
@ -242,7 +243,7 @@ xwl_get_rrmodes_from_connector_id(int drm, int32_t connector_id, int *nmode, int
ErrorF("drmModeGetConnector for connector %d failed\n", connector_id);
return NULL;
}
rrmodes = xallocarray(conn->count_modes, sizeof(RRModePtr));
rrmodes = calloc(conn->count_modes, sizeof(RRModePtr));
if (!rrmodes) {
ErrorF("Failed to allocate connector modes\n");
drmModeFreeConnector(conn);

View File

@ -358,7 +358,8 @@ output_get_rr_modes(struct xwl_output *xwl_output,
RRModePtr *rr_modes;
int i;
rr_modes = xallocarray(ARRAY_SIZE(xwl_output_fake_modes) + 1, sizeof(RRModePtr));
rr_modes = calloc(ARRAY_SIZE(xwl_output_fake_modes) + 1,
sizeof(RRModePtr));
if (!rr_modes)
goto err;
@ -1229,7 +1230,7 @@ xwl_randr_add_modes_fixed(struct xwl_output *xwl_output,
RRModePtr mode;
int i, nmodes, current;
modes = xallocarray(ARRAY_SIZE(xwl_output_fake_modes) + 1, sizeof(RRModePtr));
modes = calloc(ARRAY_SIZE(xwl_output_fake_modes) + 1, sizeof(RRModePtr));
if (!modes) {
ErrorF("Failed to allocated RandR modes\n");
return FALSE;

View File

@ -77,8 +77,6 @@ typedef struct _NewClientRec *NewClientPtr;
#define xstrdup(s) Xstrdup(s)
#define xnfstrdup(s) XNFstrdup(s)
#define xallocarray(num, size) reallocarray(NULL, (num), (size))
#endif
#include <stdio.h>

View File

@ -1193,9 +1193,9 @@ miFillSppPoly(DrawablePtr dst, GCPtr pgc, int count, /* number of points */
y = ymax - ymin + 1;
if ((count < 3) || (y <= 0))
return;
ptsOut = FirstPoint = xallocarray(y, sizeof(DDXPointRec));
width = FirstWidth = xallocarray(y, sizeof(int));
Marked = xallocarray(count, sizeof(int));
ptsOut = FirstPoint = calloc(y, sizeof(DDXPointRec));
width = FirstWidth = calloc(y, sizeof(int));
Marked = calloc(count, sizeof(int));
if (!ptsOut || !width || !Marked) {
free(Marked);
@ -1895,10 +1895,10 @@ miComputeArcs(xArc * parcs, int narcs, GCPtr pGC)
isDoubleDash = (pGC->lineStyle == LineDoubleDash);
dashOffset = pGC->dashOffset;
data = xallocarray(narcs, sizeof(struct arcData));
data = calloc(narcs, sizeof(struct arcData));
if (!data)
return NULL;
arcs = xallocarray(isDoubleDash ? 2 : 1, sizeof(*arcs));
arcs = calloc(isDoubleDash ? 2 : 1, sizeof(*arcs));
if (!arcs) {
free(data);
return NULL;
@ -3086,8 +3086,8 @@ fillSpans(DrawablePtr pDrawable, GCPtr pGC)
if (nspans == 0)
return;
xSpan = xSpans = xallocarray(nspans, sizeof(DDXPointRec));
xWidth = xWidths = xallocarray(nspans, sizeof(int));
xSpan = xSpans = calloc(nspans, sizeof(DDXPointRec));
xWidth = xWidths = calloc(nspans, sizeof(int));
if (xSpans && xWidths) {
i = 0;
f = finalSpans;
@ -3141,7 +3141,7 @@ realFindSpan(int y)
else
change = SPAN_REALLOC;
newSize = finalSize + change;
newSpans = xallocarray(newSize, sizeof(struct finalSpan *));
newSpans = calloc(newSize, sizeof(struct finalSpan *));
if (!newSpans)
return NULL;
newMiny = finalMiny;

View File

@ -465,9 +465,9 @@ miInitVisuals(VisualPtr * visualp, DepthPtr * depthp, int *nvisualp,
ndepth++;
nvisual += visuals->count;
}
depth = xallocarray(ndepth, sizeof(DepthRec));
visual = xallocarray(nvisual, sizeof(VisualRec));
preferredCVCs = xallocarray(ndepth, sizeof(int));
depth = calloc(ndepth, sizeof(DepthRec));
visual = calloc(nvisual, sizeof(VisualRec));
preferredCVCs = calloc(ndepth, sizeof(int));
if (!depth || !visual || !preferredCVCs) {
free(depth);
free(visual);
@ -488,7 +488,7 @@ miInitVisuals(VisualPtr * visualp, DepthPtr * depthp, int *nvisualp,
prefp++;
vid = NULL;
if (nvtype) {
vid = xallocarray(nvtype, sizeof(VisualID));
vid = calloc(nvtype, sizeof(VisualID));
if (!vid) {
free(depth);
free(visual);

View File

@ -60,7 +60,7 @@ miCopyRegion(DrawablePtr pSrcDrawable,
if (nbox > 1) {
/* keep ordering in each band, reverse order of bands */
pboxNew1 = xallocarray(nbox, sizeof(BoxRec));
pboxNew1 = calloc(nbox, sizeof(BoxRec));
if (!pboxNew1)
return;
pboxBase = pboxNext = pbox + nbox - 1;
@ -91,7 +91,7 @@ miCopyRegion(DrawablePtr pSrcDrawable,
if (nbox > 1) {
/* reverse order of rects in each band */
pboxNew2 = xallocarray(nbox, sizeof(BoxRec));
pboxNew2 = calloc(nbox, sizeof(BoxRec));
if (!pboxNew2) {
free(pboxNew1);
return;

View File

@ -531,7 +531,7 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
regionnumrects = RegionNumRects(prgn);
if (regionnumrects == 0)
return;
prect = xallocarray(regionnumrects, sizeof(xRectangle));
prect = calloc(regionnumrects, sizeof(xRectangle));
if (!prect)
return;

View File

@ -130,7 +130,7 @@ miPolyGlyphBlt(DrawablePtr pDrawable, GC * pGC, int x, int y, unsigned int nglyp
gcvals);
nbyLine = BitmapBytePad(width);
pbits = xallocarray(height, nbyLine);
pbits = calloc(height, nbyLine);
if (!pbits) {
dixDestroyPixmap(pPixmap, 0);
FreeScratchGC(pGCtmp);

View File

@ -410,8 +410,8 @@ miFillConvexPoly(DrawablePtr dst, GCPtr pgc, int count, DDXPointPtr ptsIn)
dy = ymax - ymin + 1;
if ((count < 3) || (dy < 0))
return TRUE;
ptsOut = FirstPoint = xallocarray(dy, sizeof(DDXPointRec));
width = FirstWidth = xallocarray(dy, sizeof(int));
ptsOut = FirstPoint = calloc(dy, sizeof(DDXPointRec));
width = FirstWidth = calloc(dy, sizeof(int));
if (!FirstPoint || !FirstWidth) {
free(FirstWidth);
free(FirstPoint);

View File

@ -65,7 +65,7 @@ miPolyPoint(DrawablePtr pDrawable, GCPtr pGC, int mode, /* Origin or Previous */
int i;
xPoint *ppt;
if (!(pwidthInit = xallocarray(npt, sizeof(int))))
if (!(pwidthInit = calloc(npt, sizeof(int))))
return;
/* make pointlist origin relative */

View File

@ -86,7 +86,7 @@ miPolyRectangle(DrawablePtr pDraw, GCPtr pGC, int nrects, xRectangle *pRects)
offset2 = pGC->lineWidth;
offset1 = offset2 >> 1;
offset3 = offset2 - offset1;
tmp = xallocarray(ntmp, sizeof(xRectangle));
tmp = calloc(ntmp, sizeof(xRectangle));
if (!tmp)
return;
t = tmp;

View File

@ -443,8 +443,8 @@ miFillUniqueSpanGroup(DrawablePtr pDraw, GCPtr pGC, SpanGroup * spanGroup)
ylength = spanGroup->ymax - ymin + 1;
/* Allocate Spans for y buckets */
yspans = xallocarray(ylength, sizeof(Spans));
ysizes = xallocarray(ylength, sizeof(int));
yspans = calloc(ylength, sizeof(Spans));
ysizes = calloc(ylength, sizeof(int));
if (!yspans || !ysizes) {
free(yspans);
@ -511,8 +511,8 @@ miFillUniqueSpanGroup(DrawablePtr pDraw, GCPtr pGC, SpanGroup * spanGroup)
} /* for i thorough Spans */
/* Now sort by x and uniquify each bucket into the final array */
points = xallocarray(count, sizeof(DDXPointRec));
widths = xallocarray(count, sizeof(int));
points = calloc(count, sizeof(DDXPointRec));
widths = calloc(count, sizeof(int));
if (!points || !widths) {
for (i = 0; i < ylength; i++) {
free(yspans[i].points);
@ -559,10 +559,10 @@ miFillUniqueSpanGroup(DrawablePtr pDraw, GCPtr pGC, SpanGroup * spanGroup)
static Bool
InitSpans(Spans * spans, size_t nspans)
{
spans->points = xallocarray(nspans, sizeof(*spans->points));
spans->points = calloc(nspans, sizeof(*spans->points));
if (!spans->points)
return FALSE;
spans->widths = xallocarray(nspans, sizeof(*spans->widths));
spans->widths = calloc(nspans, sizeof(*spans->widths));
if (!spans->widths) {
free(spans->points);
return FALSE;

View File

@ -671,7 +671,7 @@ miZeroPolyArc(DrawablePtr pDraw, GCPtr pGC, int narcs, xArc * parcs)
numPts = maxPts << 2;
dospans = (pGC->fillStyle != FillSolid);
if (dospans) {
widths = xallocarray(numPts, sizeof(int));
widths = calloc(numPts, sizeof(int));
if (!widths)
return;
maxw = 0;
@ -687,7 +687,7 @@ miZeroPolyArc(DrawablePtr pDraw, GCPtr pGC, int narcs, xArc * parcs)
(unsigned char *) pGC->dash, (int) pGC->numInDashList,
&dinfo.dashOffsetInit);
}
points = xallocarray(numPts, sizeof(DDXPointRec));
points = calloc(numPts, sizeof(DDXPointRec));
if (!points) {
if (dospans) {
free(widths);

View File

@ -148,8 +148,8 @@ miZeroLine(DrawablePtr pDraw, GCPtr pGC, int mode, /* Origin or Previous */
width = xright - xleft + 1;
height = ybottom - ytop + 1;
list_len = (height >= width) ? height : width;
pspanInit = xallocarray(list_len, sizeof(DDXPointRec));
pwidthInit = xallocarray(list_len, sizeof(int));
pspanInit = calloc(list_len, sizeof(DDXPointRec));
pwidthInit = calloc(list_len, sizeof(int));
if (!pspanInit || !pwidthInit) {
free(pspanInit);
free(pwidthInit);

View File

@ -1325,7 +1325,7 @@ damageText(DrawablePtr pDrawable,
if (!checkGCDamage(pDrawable, pGC))
return;
charinfo = xallocarray(count, sizeof(CharInfoPtr));
charinfo = calloc(count, sizeof(CharInfoPtr));
if (!charinfo)
return;

View File

@ -118,6 +118,8 @@ SOFTWARE.
#include "probes.h"
#include "xdmcp.h"
#define MAX_CONNECTIONS (1 << 16)
struct ospoll *server_poll;
Bool NewOutputPending; /* not yet attempted to write some new output */
@ -265,7 +267,12 @@ CreateWellKnownSockets(void)
LogSetDisplay();
}
ListenTransFds = xallocarray(ListenTransCount, sizeof (int));
if (ListenTransCount >= MAX_CONNECTIONS) {
FatalError ("Tried to clear too many listening sockets - OOM");
return; // mostly to keep GCC from complaining about too large alloc
}
ListenTransFds = calloc(ListenTransCount, sizeof(int));
if (ListenTransFds == NULL)
FatalError ("Failed to create listening socket array");

View File

@ -170,7 +170,7 @@ RRCrtcNotify(RRCrtcPtr crtc,
newoutputs = reallocarray(crtc->outputs,
numOutputs, sizeof(RROutputPtr));
else
newoutputs = xallocarray(numOutputs, sizeof(RROutputPtr));
newoutputs = calloc(numOutputs, sizeof(RROutputPtr));
if (!newoutputs)
return FALSE;
}
@ -1059,7 +1059,7 @@ RRCrtcGammaSetSize(RRCrtcPtr crtc, int size)
if (size == crtc->gammaSize)
return TRUE;
if (size) {
gamma = xallocarray(size, 3 * sizeof(CARD16));
gamma = calloc(size, 3 * sizeof(CARD16));
if (!gamma)
return FALSE;
}
@ -1295,7 +1295,7 @@ ProcRRSetCrtcConfig(ClientPtr client)
return BadMatch;
}
if (numOutputs) {
outputs = xallocarray(numOutputs, sizeof(RROutputPtr));
outputs = calloc(numOutputs, sizeof(RROutputPtr));
if (!outputs)
return BadAlloc;
}

View File

@ -168,7 +168,7 @@ RRModesForScreen(ScreenPtr pScreen, int *num_ret)
RRModePtr *screen_modes;
int num_screen_modes = 0;
screen_modes = xallocarray((num_modes ? num_modes : 1), sizeof(RRModePtr));
screen_modes = calloc((num_modes ? num_modes : 1), sizeof(RRModePtr));
if (!screen_modes)
return NULL;

View File

@ -130,7 +130,7 @@ RROutputSetClones(RROutputPtr output, RROutputPtr * clones, int numClones)
return TRUE;
}
if (numClones) {
newClones = xallocarray(numClones, sizeof(RROutputPtr));
newClones = calloc(numClones, sizeof(RROutputPtr));
if (!newClones)
return FALSE;
}
@ -163,7 +163,7 @@ RROutputSetModes(RROutputPtr output,
}
if (numModes) {
newModes = xallocarray(numModes, sizeof(RRModePtr));
newModes = calloc(numModes, sizeof(RRModePtr));
if (!newModes)
return FALSE;
}
@ -262,7 +262,7 @@ RROutputSetCrtcs(RROutputPtr output, RRCrtcPtr * crtcs, int numCrtcs)
return TRUE;
}
if (numCrtcs) {
newCrtcs = xallocarray(numCrtcs, sizeof(RRCrtcPtr));
newCrtcs = calloc(numCrtcs, sizeof(RRCrtcPtr));
if (!newCrtcs)
return FALSE;
}

View File

@ -207,7 +207,7 @@ RRChangeOutputProperty(RROutputPtr output, Atom property, Atom type,
if (mode == PropModeReplace || len > 0) {
void *new_data = NULL, *old_data = NULL;
new_value.data = xallocarray(total_len, size_in_bytes);
new_value.data = calloc(total_len, size_in_bytes);
if (!new_value.data && total_len && size_in_bytes) {
if (add)
RRDestroyOutputProperty(prop);
@ -379,7 +379,7 @@ RRConfigureOutputProperty(RROutputPtr output, Atom property,
return BadMatch;
}
new_values = xallocarray(num_values, sizeof(INT32));
new_values = calloc(num_values, sizeof(INT32));
if (!new_values && num_values) {
if (add)
RRDestroyOutputProperty(prop);
@ -477,7 +477,7 @@ ProcRRQueryOutputProperty(ClientPtr client)
return BadName;
if (prop->num_valid) {
extra = xallocarray(prop->num_valid, sizeof(INT32));
extra = calloc(prop->num_valid, sizeof(INT32));
if (!extra)
return BadAlloc;
}

View File

@ -347,7 +347,7 @@ RRConfigureProviderProperty(RRProviderPtr provider, Atom property,
return BadMatch;
}
new_values = xallocarray(num_values, sizeof(INT32));
new_values = calloc(num_values, sizeof(INT32));
if (!new_values && num_values) {
if (add)
RRDestroyProviderProperty(prop);
@ -396,7 +396,7 @@ ProcRRListProviderProperties(ClientPtr client)
for (prop = provider->properties; prop; prop = prop->next)
numProps++;
if (numProps)
if (!(pAtoms = xallocarray(numProps, sizeof(Atom))))
if (!(pAtoms = calloc(numProps, sizeof(Atom))))
return BadAlloc;
xRRListProviderPropertiesReply rep = {
@ -440,7 +440,7 @@ ProcRRQueryProviderProperty(ClientPtr client)
return BadName;
if (prop->num_valid) {
extra = xallocarray(prop->num_valid, sizeof(INT32));
extra = calloc(prop->num_valid, sizeof(INT32));
if (!extra)
return BadAlloc;
}

View File

@ -70,7 +70,7 @@ RRTransformSetFilter(RRTransformPtr dst,
xFixed *new_params;
if (nparams) {
new_params = xallocarray(nparams, sizeof(xFixed));
new_params = calloc(nparams, sizeof(xFixed));
if (!new_params)
return FALSE;
memcpy(new_params, params, nparams * sizeof(xFixed));

View File

@ -1086,7 +1086,7 @@ RecordAddClientToRCAP(RecordClientsAndProtocolPtr pRCAP, XID clientspec)
}
else {
XID *pNewIDs =
xallocarray(pRCAP->sizeClients + CLIENT_ARRAY_GROWTH_INCREMENT,
calloc(pRCAP->sizeClients + CLIENT_ARRAY_GROWTH_INCREMENT,
sizeof(XID));
if (!pNewIDs)
return;
@ -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));
@ -1580,7 +1580,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;
@ -2145,7 +2145,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++) {
@ -2689,7 +2689,6 @@ RecordAClientStateChange(CallbackListPtr *pcbl, void *nulldata,
NewClientInfoRec *pci = (NewClientInfoRec *) calldata;
int i;
ClientPtr pClient = pci->client;
RecordContextPtr *ppAllContextsCopy = NULL;
int numContextsCopy = 0;
switch (pClient->clientState) {
@ -2714,9 +2713,9 @@ RecordAClientStateChange(CallbackListPtr *pcbl, void *nulldata,
/* RecordDisableContext modifies contents of ppAllContexts. */
if (!(numContextsCopy = numContexts))
break;
ppAllContextsCopy = xallocarray(numContextsCopy,
sizeof(RecordContextPtr));
assert(ppAllContextsCopy);
RecordContextPtr *ppAllContextsCopy = calloc(numContextsCopy, sizeof(RecordContextPtr));
if (!ppAllContextsCopy)
return;
memcpy(ppAllContextsCopy, ppAllContexts,
numContextsCopy * sizeof(RecordContextPtr));

View File

@ -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;

View File

@ -378,7 +378,7 @@ SetPicturePictFilter(PicturePtr pPicture, PictFilterPtr pFilter,
return BadMatch;
if (nparams != pPicture->filter_nparams) {
xFixed *new_params = xallocarray(nparams, sizeof(xFixed));
xFixed *new_params = calloc(nparams, sizeof(xFixed));
if (!new_params && nparams)
return BadAlloc;

View File

@ -254,7 +254,7 @@ miInitIndexed(ScreenPtr pScreen, PictFormatPtr pFormat)
return FALSE;
pFormat->index.nvalues = num;
pFormat->index.pValues = xallocarray(num, sizeof(xIndexValue));
pFormat->index.pValues = calloc(num, sizeof(xIndexValue));
if (!pFormat->index.pValues) {
free(pIndexed);
return FALSE;

View File

@ -508,7 +508,7 @@ miTriStrip(CARD8 op,
int ntri;
ntri = npoints - 2;
tris = xallocarray(ntri, sizeof(xTriangle));
tris = calloc(ntri, sizeof(xTriangle));
if (!tris)
return;
@ -533,7 +533,7 @@ miTriFan(CARD8 op,
int ntri;
ntri = npoints - 2;
tris = xallocarray(ntri, sizeof(xTriangle));
tris = calloc(ntri, sizeof(xTriangle));
if (!tris)
return;

View File

@ -825,7 +825,7 @@ initGradient(SourcePictPtr pGradient, int stopCount,
dpos = stopPoints[i];
}
pGradient->gradient.stops = xallocarray(stopCount, sizeof(PictGradientStop));
pGradient->gradient.stops = calloc(stopCount, sizeof(PictGradientStop));
if (!pGradient->gradient.stops) {
*error = BadAlloc;
return;

View File

@ -1316,14 +1316,14 @@ ProcRenderCompositeGlyphs(ClientPtr client)
if (nglyph <= NLOCALGLYPH)
glyphsBase = glyphsLocal;
else {
glyphsBase = xallocarray(nglyph, sizeof(GlyphPtr));
glyphsBase = calloc(nglyph, sizeof(GlyphPtr));
if (!glyphsBase)
return BadAlloc;
}
if (nlist <= NLOCALDELTA)
listsBase = listsLocal;
else {
listsBase = xallocarray(nlist, sizeof(GlyphListRec));
listsBase = calloc(nlist, sizeof(GlyphListRec));
if (!listsBase) {
rc = BadAlloc;
goto bail;
@ -1799,7 +1799,7 @@ ProcRenderCreateAnimCursor(ClientPtr client)
ncursor =
(client->req_len -
(bytes_to_int32(sizeof(xRenderCreateAnimCursorReq)))) >> 1;
cursors = xallocarray(ncursor, sizeof(CursorPtr) + sizeof(CARD32));
cursors = calloc(ncursor, sizeof(CursorPtr) + sizeof(CARD32));
if (!cursors)
return BadAlloc;
deltas = (CARD32 *) (cursors + ncursor);

View File

@ -746,7 +746,7 @@ ProcXFixesExpandRegion(ClientPtr client)
nBoxes = RegionNumRects(pSource);
pSrc = RegionRects(pSource);
if (nBoxes) {
pTmp = xallocarray(nBoxes, sizeof(BoxRec));
pTmp = calloc(nBoxes, sizeof(BoxRec));
if (!pTmp)
return BadAlloc;
for (i = 0; i < nBoxes; i++) {

View File

@ -93,7 +93,7 @@ InputLineAddChar(InputLine * line, int ch)
{
if (line->num_line >= line->sz_line) {
if (line->line == line->buf) {
line->line = xallocarray(line->sz_line, 2);
line->line = calloc(line->sz_line, 2);
memcpy(line->line, line->buf, line->sz_line);
}
else {
@ -896,11 +896,15 @@ XkbRF_AddRule(XkbRF_RulesPtr rules)
rules->sz_rules = 16;
rules->num_rules = 0;
rules->rules = calloc(rules->sz_rules, sizeof(XkbRF_RuleRec));
if (!(rules->rules))
return NULL;
}
else if (rules->num_rules >= rules->sz_rules) {
rules->sz_rules *= 2;
rules->rules = reallocarray(rules->rules,
rules->sz_rules, sizeof(XkbRF_RuleRec));
if (!(rules->rules))
return NULL;
}
if (!rules->rules) {
rules->sz_rules = rules->num_rules = 0;
@ -918,11 +922,15 @@ XkbRF_AddGroup(XkbRF_RulesPtr rules)
rules->sz_groups = 16;
rules->num_groups = 0;
rules->groups = calloc(rules->sz_groups, sizeof(XkbRF_GroupRec));
if (!(rules->groups))
return NULL;
}
else if (rules->num_groups >= rules->sz_groups) {
rules->sz_groups *= 2;
rules->groups = reallocarray(rules->groups,
rules->sz_groups, sizeof(XkbRF_GroupRec));
if (!(rules->groups))
return NULL;
}
if (!rules->groups) {
rules->sz_groups = rules->num_groups = 0;

View File

@ -2837,7 +2837,7 @@ XkbSendCompatMap(ClientPtr client,
int size;
if (rep->length > 0) {
data = xallocarray(rep->length, 4);
data = calloc(rep->length, 4);
if (data) {
register unsigned i, bit;
xkbModsWireDesc *grp;
@ -3224,7 +3224,7 @@ XkbSendIndicatorMap(ClientPtr client,
if (rep->length > 0) {
CARD8 *to;
to = map = xallocarray(rep->length, 4);
to = map = calloc(rep->length, 4);
if (map) {
xkbIndicatorMapWireDesc *wire = (xkbIndicatorMapWireDesc *) to;
@ -5036,7 +5036,7 @@ XkbSendGeometry(ClientPtr client,
int len;
if (geom != NULL) {
start = desc = xallocarray(rep->length, 4);
start = desc = calloc(rep->length, 4);
if (!start)
return BadAlloc;
len = rep->length * 4;

View File

@ -1065,7 +1065,7 @@ _XkbCopyClientMap(XkbDescPtr src, XkbDescPtr dst)
}
else if (!dtype->map_count || !dtype->map ||
i >= dst->map->num_types) {
tmp = xallocarray(stype->map_count,
tmp = calloc(stype->map_count,
sizeof(XkbKTMapEntryRec));
if (!tmp)
return FALSE;
@ -1094,8 +1094,7 @@ _XkbCopyClientMap(XkbDescPtr src, XkbDescPtr dst)
}
else if (!dtype->preserve || !dtype->map_count ||
i >= dst->map->num_types) {
tmp = xallocarray(stype->map_count,
sizeof(XkbModsRec));
tmp = calloc(stype->map_count, sizeof(XkbModsRec));
if (!tmp)
return FALSE;
dtype->preserve = tmp;
@ -1605,7 +1604,7 @@ _XkbCopyGeom(XkbDescPtr src, XkbDescPtr dst)
j < sshape->num_outlines;
j++, soutline++, doutline++) {
if (soutline->num_points) {
tmp = xallocarray(soutline->num_points,
tmp = calloc(soutline->num_points,
sizeof(XkbPointRec));
if (!tmp)
return FALSE;
@ -1733,7 +1732,7 @@ _XkbCopyGeom(XkbDescPtr src, XkbDescPtr dst)
for (j = 0, srow = ssection->rows, drow = dsection->rows;
j < ssection->num_rows; j++, srow++, drow++) {
if (srow->num_keys) {
tmp = xallocarray(srow->num_keys, sizeof(XkbKeyRec));
tmp = calloc(srow->num_keys, sizeof(XkbKeyRec));
if (!tmp)
return FALSE;
drow->keys = tmp;