diff --git a/dix/atom.c b/dix/atom.c index 194b2baec..120bf95cc 100644 --- a/dix/atom.c +++ b/dix/atom.c @@ -100,9 +100,7 @@ MakeAtom(const char *string, unsigned len, Bool makeit) } } if (makeit) { - NodePtr nd; - - nd = malloc(sizeof(NodeRec)); + NodePtr nd = calloc(1, sizeof(NodeRec)); if (!nd) return BAD_RESOURCE; if (lastAtom < XA_LAST_PREDEFINED) { diff --git a/dix/colormap.c b/dix/colormap.c index 9a8be28e2..fcb17958f 100644 --- a/dix/colormap.c +++ b/dix/colormap.c @@ -266,7 +266,7 @@ CreateColormap(Colormap mid, ScreenPtr pScreen, VisualPtr pVisual, sizebytes *= 3; sizebytes += sizeof(ColormapRec); if (mid == pScreen->defColormap) { - pmap = malloc(sizebytes); + pmap = calloc(1, sizebytes); if (!pmap) return BadAlloc; if (!dixAllocatePrivates(&pmap->devPrivates, PRIVATE_COLORMAP)) { @@ -1087,9 +1087,7 @@ AllocColor(ColormapPtr pmap, * should be freed when the client dies */ if ((pmap->numPixelsRed[client] == 1) && (CLIENT_ID(pmap->mid) != client) && !(pmap->flags & CM_BeingCreated)) { - colorResource *pcr; - - pcr = malloc(sizeof(colorResource)); + colorResource *pcr = calloc(1, sizeof(colorResource)); if (!pcr) { (void) FreeColors(pmap, client, 1, pPix, (Pixel) 0); return BadAlloc; @@ -1507,7 +1505,7 @@ AllocColorCells(int client, ColormapPtr pmap, int colors, int planes, if (pmap->class == DirectColor) oldcount += pmap->numPixelsGreen[client] + pmap->numPixelsBlue[client]; if (!oldcount && (CLIENT_ID(pmap->mid) != client)) { - pcr = malloc(sizeof(colorResource)); + pcr = calloc(1, sizeof(colorResource)); if (!pcr) return BadAlloc; } @@ -1574,7 +1572,7 @@ AllocColorPlanes(int client, ColormapPtr pmap, int colors, if (class == DirectColor) oldcount += pmap->numPixelsGreen[client] + pmap->numPixelsBlue[client]; if (!oldcount && (CLIENT_ID(pmap->mid) != client)) { - pcr = malloc(sizeof(colorResource)); + pcr = calloc(1, sizeof(colorResource)); if (!pcr) return BadAlloc; } @@ -1977,7 +1975,7 @@ AllocShared(ColormapPtr pmap, Pixel * ppix, int c, int r, int g, int b, return FALSE; ppshared = psharedList; for (z = npixShared; --z >= 0;) { - if (!(ppshared[z] = malloc(sizeof(SHAREDCOLOR)))) { + if (!(ppshared[z] = calloc(1, sizeof(SHAREDCOLOR)))) { for (z++; z < npixShared; z++) free(ppshared[z]); free(psharedList); diff --git a/dix/cursor.c b/dix/cursor.c index f12c50971..d9ebd146f 100644 --- a/dix/cursor.c +++ b/dix/cursor.c @@ -376,7 +376,7 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar, unsigned char *mskptr; n = BitmapBytePad(cm.width) * (long) cm.height; - mskptr = mskbits = malloc(n); + mskptr = mskbits = calloc(1, n); if (!mskptr) return BadAlloc; while (--n >= 0) @@ -427,7 +427,7 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar, bits->refcnt = -1; else { bits->refcnt = 1; - pShare = malloc(sizeof(GlyphShare)); + pShare = calloc(1, sizeof(GlyphShare)); if (!pShare) { FreeCursorBits(bits); return BadAlloc; diff --git a/dix/devices.c b/dix/devices.c index 310364730..c005693f4 100644 --- a/dix/devices.c +++ b/dix/devices.c @@ -1203,7 +1203,7 @@ CloseOneDevice(const DeviceIntPtr dev, DeviceIntPtr *listHead) * the removal of the device. * * No PresenceNotify is sent for device that the client never saw. This can - * happen if a malloc fails during the addition of master devices. If + * happen if a calloc fails during the addition of master devices. If * dev->init is FALSE it means the client never received a DeviceAdded event, * so let's not send a DeviceRemoved event either. * @@ -1476,12 +1476,10 @@ InitPointerAccelerationScheme(DeviceIntPtr dev, int scheme) Bool InitFocusClassDeviceStruct(DeviceIntPtr dev) { - FocusClassPtr focc; - BUG_RETURN_VAL(dev == NULL, FALSE); BUG_RETURN_VAL(dev->focus != NULL, FALSE); - focc = malloc(sizeof(FocusClassRec)); + FocusClassPtr focc = calloc(1, sizeof(FocusClassRec)); if (!focc) return FALSE; UpdateCurrentTimeIf(); @@ -1499,11 +1497,9 @@ InitFocusClassDeviceStruct(DeviceIntPtr dev) Bool InitPtrFeedbackClassDeviceStruct(DeviceIntPtr dev, PtrCtrlProcPtr controlProc) { - PtrFeedbackPtr feedc; - BUG_RETURN_VAL(dev == NULL, FALSE); - feedc = malloc(sizeof(PtrFeedbackClassRec)); + PtrFeedbackPtr feedc = calloc(1, sizeof(PtrFeedbackClassRec)); if (!feedc) return FALSE; feedc->CtrlProc = controlProc; @@ -1542,11 +1538,10 @@ InitStringFeedbackClassDeviceStruct(DeviceIntPtr dev, KeySym * symbols) { int i; - StringFeedbackPtr feedc; BUG_RETURN_VAL(dev == NULL, FALSE); - feedc = malloc(sizeof(StringFeedbackClassRec)); + StringFeedbackPtr feedc = calloc(1, sizeof(StringFeedbackClassRec)); if (!feedc) return FALSE; feedc->CtrlProc = controlProc; @@ -1578,11 +1573,9 @@ Bool InitBellFeedbackClassDeviceStruct(DeviceIntPtr dev, BellProcPtr bellProc, BellCtrlProcPtr controlProc) { - BellFeedbackPtr feedc; - BUG_RETURN_VAL(dev == NULL, FALSE); - feedc = malloc(sizeof(BellFeedbackClassRec)); + BellFeedbackPtr feedc = calloc(1, sizeof(BellFeedbackClassRec)); if (!feedc) return FALSE; feedc->CtrlProc = controlProc; @@ -1599,11 +1592,9 @@ InitBellFeedbackClassDeviceStruct(DeviceIntPtr dev, BellProcPtr bellProc, Bool InitLedFeedbackClassDeviceStruct(DeviceIntPtr dev, LedCtrlProcPtr controlProc) { - LedFeedbackPtr feedc; - BUG_RETURN_VAL(dev == NULL, FALSE); - feedc = malloc(sizeof(LedFeedbackClassRec)); + LedFeedbackPtr feedc = calloc(1, sizeof(LedFeedbackClassRec)); if (!feedc) return FALSE; feedc->CtrlProc = controlProc; @@ -1621,11 +1612,9 @@ Bool InitIntegerFeedbackClassDeviceStruct(DeviceIntPtr dev, IntegerCtrlProcPtr controlProc) { - IntegerFeedbackPtr feedc; - BUG_RETURN_VAL(dev == NULL, FALSE); - feedc = malloc(sizeof(IntegerFeedbackClassRec)); + IntegerFeedbackPtr feedc = calloc(1, sizeof(IntegerFeedbackClassRec)); if (!feedc) return FALSE; feedc->CtrlProc = controlProc; diff --git a/dix/dispatch.c b/dix/dispatch.c index b3e5feacc..a1673ab76 100644 --- a/dix/dispatch.c +++ b/dix/dispatch.c @@ -643,7 +643,7 @@ CreateConnectionBlock(void) pad_to_int32(setup.nbytesVendor) + (setup.numFormats * sizeof(xPixmapFormat)) + (setup.numRoots * sizeof(xWindowRoot)); - ConnectionInfo = malloc(lenofblock); + ConnectionInfo = calloc(1, lenofblock); if (!ConnectionInfo) return FALSE; @@ -2574,7 +2574,6 @@ ProcUninstallColormap(ClientPtr client) int ProcListInstalledColormaps(ClientPtr client) { - xListInstalledColormapsReply *preply; int nummaps, rc; WindowPtr pWin; @@ -2589,7 +2588,8 @@ ProcListInstalledColormaps(ClientPtr client) if (rc != Success) return rc; - preply = malloc(sizeof(xListInstalledColormapsReply) + + xListInstalledColormapsReply *preply = calloc(1, + sizeof(xListInstalledColormapsReply) + pWin->drawable.pScreen->maxInstalledCmaps * sizeof(Colormap)); if (!preply) @@ -2704,7 +2704,7 @@ ProcAllocColorCells(ClientPtr client) if (rc == Success) { int npixels, nmasks; long length; - Pixel *ppixels, *pmasks; + Pixel *pmasks; npixels = stuff->colors; if (!npixels) { @@ -2717,7 +2717,7 @@ ProcAllocColorCells(ClientPtr client) } nmasks = stuff->planes; length = ((long) npixels + (long) nmasks) * sizeof(Pixel); - ppixels = malloc(length); + Pixel *ppixels = calloc(1, length); if (!ppixels) return BadAlloc; pmasks = ppixels + npixels; @@ -2766,7 +2766,6 @@ ProcAllocColorPlanes(ClientPtr client) xAllocColorPlanesReply acpr; int npixels; long length; - Pixel *ppixels; npixels = stuff->colors; if (!npixels) { @@ -2784,7 +2783,7 @@ ProcAllocColorPlanes(ClientPtr client) }; length = (long) npixels *sizeof(Pixel); - ppixels = malloc(length); + Pixel *ppixels = calloc(1, length); if (!ppixels) return BadAlloc; if ((rc = AllocColorPlanes(client->index, pcmp, npixels, @@ -2996,7 +2995,6 @@ ProcCreateCursor(ClientPtr client) PixmapPtr src; PixmapPtr msk; unsigned char *srcbits; - unsigned char *mskbits; unsigned short width, height; long n; CursorMetricRec cm; @@ -3044,7 +3042,8 @@ ProcCreateCursor(ClientPtr client) if (!srcbits) return BadAlloc; n = BitmapBytePad(width) * height; - mskbits = malloc(n); + + unsigned char *mskbits = calloc(1, n); if (!mskbits) { free(srcbits); return BadAlloc; diff --git a/dix/dixfonts.c b/dix/dixfonts.c index dd617d99c..ee349c42e 100644 --- a/dix/dixfonts.c +++ b/dix/dixfonts.c @@ -379,7 +379,6 @@ int OpenFont(ClientPtr client, XID fid, Mask flags, unsigned lenfname, const char *pfontname) { - OFclosurePtr c; int i; FontPtr cached = (FontPtr) 0; @@ -412,10 +411,10 @@ OpenFont(ClientPtr client, XID fid, Mask flags, unsigned lenfname, return Success; } } - c = malloc(sizeof(OFclosureRec)); + OFclosurePtr c = calloc(1, sizeof(OFclosureRec)); if (!c) return BadAlloc; - c->fontname = malloc(lenfname); + c->fontname = calloc(1, lenfname); c->origFontName = pfontname; c->origFontNameLen = lenfname; if (!c->fontname) { @@ -644,7 +643,7 @@ doListFontsAndAliases(ClientPtr client, LFclosurePtr c) } if (err == FontNameAlias) { free(resolved); - resolved = malloc(resolvedlen + 1); + resolved = calloc(1, resolvedlen + 1); if (resolved) memcpy(resolved, tmpname, resolvedlen + 1); } @@ -694,7 +693,7 @@ doListFontsAndAliases(ClientPtr client, LFclosurePtr c) c->saved = c->current; c->haveSaved = TRUE; free(c->savedName); - c->savedName = malloc(namelen + 1); + c->savedName = calloc(1, namelen + 1); if (c->savedName) memcpy(c->savedName, name, namelen + 1); c->savedNameLen = namelen; @@ -756,7 +755,7 @@ doListFontsAndAliases(ClientPtr client, LFclosurePtr c) .sequenceNumber = client->sequence }; - bufptr = bufferStart = malloc(reply.length << 2); + bufptr = bufferStart = calloc(1, reply.length << 2); if (!bufptr && reply.length) { SendErrorToClient(client, X_ListFonts, 0, 0, BadAlloc); @@ -814,7 +813,7 @@ ListFonts(ClientPtr client, unsigned char *pattern, unsigned length, if (i != Success) return i; - if (!(c = malloc(sizeof *c))) + if (!(c = calloc(1, sizeof *c))) return BadAlloc; c->fpe_list = xallocarray(num_fpes, sizeof(FontPathElementPtr)); if (!c->fpe_list) { @@ -934,7 +933,7 @@ doListFontsWithInfo(ClientPtr client, LFWIclosurePtr c) c->haveSaved = TRUE; c->savedNumFonts = numFonts; free(c->savedName); - c->savedName = malloc(namelen + 1); + c->savedName = calloc(1, namelen + 1); if (c->savedName) memcpy(c->savedName, name, namelen + 1); aliascount = 20; @@ -1060,7 +1059,7 @@ StartListFontsWithInfo(ClientPtr client, int length, unsigned char *pattern, if (i != Success) return i; - if (!(c = malloc(sizeof *c))) + if (!(c = calloc(1, sizeof *c))) goto badAlloc; c->fpe_list = xallocarray(num_fpes, sizeof(FontPathElementPtr)); if (!c->fpe_list) { @@ -1219,7 +1218,7 @@ doPolyText(ClientPtr client, PTclosurePtr c) /* We're putting the client to sleep. We need to do a few things to ensure successful and atomic-appearing execution of the remainder of the request. First, copy the remainder of the - request into a safe malloc'd area. Second, create a scratch GC + request into a safe calloc'd area. Second, create a scratch GC to use for the remainder of the request. Third, mark all fonts referenced in the remainder of the request to prevent their deallocation. Fourth, make the original GC look like the @@ -1231,9 +1230,9 @@ doPolyText(ClientPtr client, PTclosurePtr c) indicated by client_state = START_SLEEP. */ /* Step 1 */ - /* Allocate a malloc'd closure structure to replace + /* Allocate a calloc'd closure structure to replace the local one we were passed */ - new_closure = malloc(sizeof(PTclosureRec)); + new_closure = calloc(1, sizeof(PTclosureRec)); if (!new_closure) { err = BadAlloc; goto bail; @@ -1241,7 +1240,7 @@ doPolyText(ClientPtr client, PTclosurePtr c) *new_closure = *c; len = new_closure->endReq - new_closure->pElt; - new_closure->data = malloc(len); + new_closure->data = calloc(1, len); if (!new_closure->data) { free(new_closure); err = BadAlloc; @@ -1411,7 +1410,6 @@ doImageText(ClientPtr client, ITclosurePtr c) if (!ClientIsAsleep(client)) { GC *pGC; unsigned char *data; - ITclosurePtr new_closure; ITclosurePtr old_closure; /* We're putting the client to sleep. We need to @@ -1419,7 +1417,7 @@ doImageText(ClientPtr client, ITclosurePtr c) in doPolyText, but much simpler because the request structure is much simpler. */ - new_closure = malloc(sizeof(ITclosureRec)); + ITclosurePtr new_closure = calloc(1, sizeof(ITclosureRec)); if (!new_closure) { err = BadAlloc; goto bail; @@ -1617,13 +1615,12 @@ SetFontPathElements(int npaths, unsigned char *paths, int *bad, Bool persist) } /* if error or can't do it, act like it's a new one */ if (!fpe) { - char *name; - fpe = malloc(sizeof(FontPathElementRec)); + fpe = calloc(1, sizeof(FontPathElementRec)); if (!fpe) { err = BadAlloc; goto bail; } - name = malloc(len + 1); + char *name = calloc(1, len + 1); if (!name) { free(fpe); err = BadAlloc; @@ -1730,7 +1727,7 @@ SetDefaultFontPath(const char *path) /* get enough for string, plus values -- use up commas */ len = strlen(temp_path) + 1; - nump = cp = newpath = malloc(len); + nump = cp = newpath = calloc(1, len); if (!newpath) { free(temp_path); return BadAlloc; diff --git a/dix/dixutils.c b/dix/dixutils.c index 3b98ced0e..f45a3eb33 100644 --- a/dix/dixutils.c +++ b/dix/dixutils.c @@ -532,9 +532,7 @@ Bool QueueWorkProc(Bool (*function) (ClientPtr pClient, void *closure), ClientPtr client, void *closure) { - WorkQueuePtr q; - - q = malloc(sizeof *q); + WorkQueuePtr q = calloc(1, sizeof *q); if (!q) return FALSE; q->function = function; @@ -566,9 +564,7 @@ static SleepQueuePtr sleepQueue = NULL; Bool ClientSleep(ClientPtr client, ClientSleepProcPtr function, void *closure) { - SleepQueuePtr q; - - q = malloc(sizeof *q); + SleepQueuePtr q = calloc(1, sizeof *q); if (!q) return FALSE; @@ -655,9 +651,7 @@ static CallbackListPtr **listsToCleanup = NULL; static Bool _AddCallback(CallbackListPtr *pcbl, CallbackProcPtr callback, void *data) { - CallbackPtr cbr; - - cbr = malloc(sizeof(CallbackRec)); + CallbackPtr cbr = calloc(1, sizeof(CallbackRec)); if (!cbr) return FALSE; cbr->proc = callback; @@ -777,12 +771,12 @@ _DeleteCallbackList(CallbackListPtr *pcbl) static Bool CreateCallbackList(CallbackListPtr *pcbl) { - CallbackListPtr cbl; int i; if (!pcbl) return FALSE; - cbl = malloc(sizeof(CallbackListRec)); + + CallbackListPtr cbl = calloc(1, sizeof(CallbackListRec)); if (!cbl) return FALSE; cbl->inCallback = 0; diff --git a/dix/events.c b/dix/events.c index c146c823b..16d95b0c6 100644 --- a/dix/events.c +++ b/dix/events.c @@ -1141,7 +1141,6 @@ void EnqueueEvent(InternalEvent *ev, DeviceIntPtr device) { QdEventPtr tail = NULL; - QdEventPtr qe; SpritePtr pSprite = device->spriteInfo->sprite; int eventlen; DeviceEvent *event = &ev->device_event; @@ -1202,7 +1201,7 @@ EnqueueEvent(InternalEvent *ev, DeviceIntPtr device) eventlen = sizeof(InternalEvent); - qe = malloc(sizeof(QdEventRec) + eventlen); + QdEventPtr qe = calloc(1, sizeof(QdEventRec) + eventlen); if (!qe) return; xorg_list_init(&qe->next); @@ -4588,7 +4587,7 @@ EventSelectForWindow(WindowPtr pWin, ClientPtr client, Mask mask) check = 0; if (!pWin->optional && !MakeWindowOptional(pWin)) return BadAlloc; - others = malloc(sizeof(OtherClients)); + others = calloc(1, sizeof(OtherClients)); if (!others) return BadAlloc; others->mask = mask; diff --git a/dix/extension.c b/dix/extension.c index fd1439957..68c073e7f 100644 --- a/dix/extension.c +++ b/dix/extension.c @@ -283,7 +283,7 @@ ProcListExtensions(ClientPtr client) reply.nExtensions += 1; } reply.length = bytes_to_int32(total_length); - buffer = bufptr = malloc(total_length); + buffer = bufptr = calloc(1, total_length); if (!buffer) return BadAlloc; for (i = 0; i < NumExtensions; i++) { diff --git a/dix/gc.c b/dix/gc.c index ab5844353..43ed2fe65 100644 --- a/dix/gc.c +++ b/dix/gc.c @@ -361,9 +361,7 @@ ChangeGC(ClientPtr client, GC * pGC, BITS32 mask, ChangeGCValPtr pUnion) } } else if (newdash != 0) { - unsigned char *dash; - - dash = malloc(2 * sizeof(unsigned char)); + unsigned char *dash = calloc(2, sizeof(unsigned char)); if (dash) { if (pGC->dash != DefaultDash) free(pGC->dash); @@ -726,10 +724,8 @@ CopyGC(GC * pgcSrc, GC * pgcDst, BITS32 mask) } } else { - unsigned char *dash; unsigned int i; - - dash = malloc(pgcSrc->numInDashList * sizeof(unsigned char)); + unsigned char *dash = calloc(pgcSrc->numInDashList, sizeof(unsigned char)); if (dash) { if (pgcDst->dash != DefaultDash) free(pgcDst->dash); @@ -924,9 +920,9 @@ SetDashes(GCPtr pGC, unsigned offset, unsigned ndash, unsigned char *pdash) } if (ndash & 1) - p = malloc(2 * ndash * sizeof(unsigned char)); + p = calloc(2 * ndash, sizeof(unsigned char)); else - p = malloc(ndash * sizeof(unsigned char)); + p = calloc(ndash, sizeof(unsigned char)); if (!p) return BadAlloc; @@ -1005,13 +1001,13 @@ SetClipRects(GCPtr pGC, int xOrigin, int yOrigin, int nrects, xRectangle *prects, int ordering) { int newct, size; - xRectangle *prectsNew; newct = VerifyRectOrder(nrects, prects, ordering); if (newct < 0) return BadMatch; size = nrects * sizeof(xRectangle); - prectsNew = malloc(size); + + xRectangle *prectsNew = calloc(1, size); if (!prectsNew && size) return BadAlloc; diff --git a/dix/getevents.c b/dix/getevents.c index 34014ffbb..58ace1831 100644 --- a/dix/getevents.c +++ b/dix/getevents.c @@ -433,7 +433,7 @@ GetMotionHistory(DeviceIntPtr pDev, xTimecoord ** buff, unsigned long start, else size = (sizeof(INT32) * pDev->valuator->numAxes) + sizeof(Time); - *buff = malloc(size * pDev->valuator->numMotionEvents); + *buff = calloc(size, pDev->valuator->numMotionEvents); if (!(*buff)) return 0; obuff = (char *) *buff; diff --git a/dix/grabs.c b/dix/grabs.c index 8409a0bf8..581acd828 100644 --- a/dix/grabs.c +++ b/dix/grabs.c @@ -279,7 +279,7 @@ CopyGrab(GrabPtr dst, const GrabPtr src) if (src->modifiersDetail.pMask) { int len = MasksPerDetailMask * sizeof(Mask); - mdetails_mask = malloc(len); + mdetails_mask = calloc(1, len); if (!mdetails_mask) return FALSE; memcpy(mdetails_mask, src->modifiersDetail.pMask, len); @@ -288,7 +288,7 @@ CopyGrab(GrabPtr dst, const GrabPtr src) if (src->detail.pMask) { int len = MasksPerDetailMask * sizeof(Mask); - details_mask = malloc(len); + details_mask = calloc(1, len); if (!details_mask) { free(mdetails_mask); return FALSE; @@ -345,10 +345,9 @@ DeletePassiveGrab(void *value, XID id) static Mask * DeleteDetailFromMask(Mask *pDetailMask, unsigned int detail) { - Mask *mask; int i; - mask = malloc(sizeof(Mask) * MasksPerDetailMask); + Mask *mask = calloc(MasksPerDetailMask, sizeof(Mask)); if (mask) { if (pDetailMask) for (i = 0; i < MasksPerDetailMask; i++) diff --git a/dix/privates.c b/dix/privates.c index 62309d769..8f025e239 100644 --- a/dix/privates.c +++ b/dix/privates.c @@ -469,7 +469,6 @@ _dixAllocateObjectWithPrivates(unsigned baseSize, unsigned clear, unsigned offset, DevPrivateType type) { unsigned totalSize; - void *object; PrivatePtr privates; PrivatePtr *devPrivates; @@ -480,7 +479,7 @@ _dixAllocateObjectWithPrivates(unsigned baseSize, unsigned clear, /* round up so that void * is aligned */ baseSize = (baseSize + sizeof(void *) - 1) & ~(sizeof(void *) - 1); totalSize = baseSize + global_keys[type].offset; - object = malloc(totalSize); + void *object = calloc(1, totalSize); if (!object) return NULL; @@ -512,7 +511,7 @@ dixAllocatePrivates(PrivatePtr *privates, DevPrivateType type) p = NULL; } else { - if (!(p = malloc(size))) + if (!(p = calloc(1, size))) return FALSE; } @@ -692,7 +691,6 @@ _dixAllocateScreenObjectWithPrivates(ScreenPtr pScreen, DevPrivateType type) { unsigned totalSize; - void *object; PrivatePtr privates; PrivatePtr *devPrivates; int privates_size; @@ -708,7 +706,7 @@ _dixAllocateScreenObjectWithPrivates(ScreenPtr pScreen, /* round up so that pointer is aligned */ baseSize = (baseSize + sizeof(void *) - 1) & ~(sizeof(void *) - 1); totalSize = baseSize + privates_size; - object = malloc(totalSize); + void *object = calloc(1, totalSize); if (!object) return NULL; diff --git a/dix/property.c b/dix/property.c index e5e579f95..99f29c30e 100644 --- a/dix/property.c +++ b/dix/property.c @@ -261,7 +261,6 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property, PropertyPtr pProp; PropertyRec savedProp; int sizeInBytes, totalSize, rc; - unsigned char *data; Mask access_mode; sizeInBytes = format >> 3; @@ -277,7 +276,7 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property, pProp = dixAllocateObjectWithPrivates(PropertyRec, PRIVATE_PROPERTY); if (!pProp) return BadAlloc; - data = malloc(totalSize); + unsigned char *data = calloc(1, totalSize); if (totalSize) { if (!data) { dixFreeObjectWithPrivates(pProp, PRIVATE_PROPERTY); @@ -316,7 +315,7 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property, savedProp = *pProp; if (mode == PropModeReplace) { - data = malloc(totalSize); + unsigned char *data = calloc(1, totalSize); if (totalSize) { if (!data) return BadAlloc; @@ -331,7 +330,7 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property, /* do nothing */ } else if (mode == PropModeAppend) { - data = xallocarray(pProp->size + len, sizeInBytes); + unsigned char *data = calloc(pProp->size + len, sizeInBytes); if (!data) return BadAlloc; memcpy(data, pProp->data, pProp->size * sizeInBytes); @@ -340,7 +339,7 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property, pProp->size += len; } else if (mode == PropModePrepend) { - data = xallocarray(len + pProp->size, sizeInBytes); + unsigned char *data = calloc(len + pProp->size, sizeInBytes); if (!data) return BadAlloc; memcpy(data + totalSize, pProp->data, pProp->size * sizeInBytes); diff --git a/dix/region.c b/dix/region.c index 00c804ea2..2dbf2abc3 100644 --- a/dix/region.c +++ b/dix/region.c @@ -227,16 +227,14 @@ InitRegions(void) /***************************************************************** * RegionCreate(rect, size) - * This routine does a simple malloc to make a structure of + * This routine does a simple calloc to make a structure of * REGION of "size" number of rectangles. *****************************************************************/ RegionPtr RegionCreate(BoxPtr rect, int size) { - RegionPtr pReg; - - pReg = (RegionPtr) malloc(sizeof(RegionRec)); + RegionPtr pReg = calloc(1, sizeof(RegionRec)); if (!pReg) return &RegionBrokenRegion; @@ -348,7 +346,7 @@ RegionRectAlloc(RegionPtr pRgn, int n) if (!pRgn->data) { n++; rgnSize = RegionSizeof(n); - pRgn->data = (rgnSize > 0) ? malloc(rgnSize) : NULL; + pRgn->data = (rgnSize > 0) ? calloc(1, rgnSize) : NULL; if (!pRgn->data) return RegionBreak(pRgn); pRgn->data->numRects = 1; @@ -356,7 +354,7 @@ RegionRectAlloc(RegionPtr pRgn, int n) } else if (!pRgn->data->size) { rgnSize = RegionSizeof(n); - pRgn->data = (rgnSize > 0) ? malloc(rgnSize) : NULL; + pRgn->data = (rgnSize > 0) ? calloc(1, rgnSize) : NULL; if (!pRgn->data) return RegionBreak(pRgn); pRgn->data->numRects = 0; @@ -1142,7 +1140,6 @@ RegionValidate(RegionPtr badreg, Bool *pOverlap) } RegionInfo; int numRects; /* Original numRects for badreg */ - RegionInfo *ri; /* Array of current regions */ int numRI; /* Number of entries used in ri */ int sizeRI; /* Number of entries available in ri */ int i; /* Index into rects */ @@ -1185,7 +1182,7 @@ RegionValidate(RegionPtr badreg, Bool *pOverlap) /* Set up the first region to be the first rectangle in badreg */ /* Note that step 2 code will never overflow the ri[0].reg rects array */ - ri = (RegionInfo *) malloc(4 * sizeof(RegionInfo)); + RegionInfo *ri = calloc(4, sizeof(RegionInfo)); if (!ri) return RegionBreak(badreg); sizeRI = 4; @@ -1316,7 +1313,6 @@ RegionFromRects(int nrects, xRectangle *prect, int ctype) RegionPtr pRgn; size_t rgnSize; - RegDataPtr pData; BoxPtr pBox; int i; int x1, y1, x2, y2; @@ -1343,7 +1339,7 @@ RegionFromRects(int nrects, xRectangle *prect, int ctype) return pRgn; } rgnSize = RegionSizeof(nrects); - pData = (rgnSize > 0) ? malloc(rgnSize) : NULL; + RegDataPtr pData = (rgnSize > 0) ? calloc(1, rgnSize) : NULL; if (!pData) { RegionBreak(pRgn); return pRgn; diff --git a/dix/resource.c b/dix/resource.c index 7542f0c42..265573587 100644 --- a/dix/resource.c +++ b/dix/resource.c @@ -649,13 +649,13 @@ InitClientResources(ClientPtr client) lastResourceClass = RC_LASTPREDEF; TypeMask = RC_LASTPREDEF - 1; free(resourceTypes); - resourceTypes = malloc(sizeof(predefTypes)); + resourceTypes = calloc(1, sizeof(predefTypes)); if (!resourceTypes) return FALSE; memcpy(resourceTypes, predefTypes, sizeof(predefTypes)); } clientTable[i = client->index].resources = - malloc(INITBUCKETS * sizeof(ResourcePtr)); + calloc(INITBUCKETS, sizeof(ResourcePtr)); if (!clientTable[i].resources) return FALSE; clientTable[i].buckets = INITBUCKETS; @@ -808,7 +808,7 @@ AddResource(XID id, RESTYPE type, void *value) { int client; ClientResourceRec *rrec; - ResourcePtr res, *head; + ResourcePtr *head; #ifdef XSERVER_DTRACE XSERVER_RESOURCE_ALLOC(id, type, value, TypeNameString(type)); @@ -823,7 +823,7 @@ AddResource(XID id, RESTYPE type, void *value) if ((rrec->elements >= 4 * rrec->buckets) && (rrec->hashsize < MAXHASHSIZE)) RebuildTable(client); head = &rrec->resources[HashResourceID(id, clientTable[client].hashsize)]; - res = malloc(sizeof(ResourceRec)); + ResourcePtr res = calloc(1, sizeof(ResourceRec)); if (!res) { (*resourceTypes[type & TypeMask].deleteFunc) (value, id); return FALSE; diff --git a/dix/swaprep.c b/dix/swaprep.c index b9afa14a2..2f9c636d3 100644 --- a/dix/swaprep.c +++ b/dix/swaprep.c @@ -94,7 +94,7 @@ CopySwap32Write(ClientPtr pClient, int size, CARD32 *pbuf) CARD32 tmpbuf[1]; /* Allocate as big a buffer as we can... */ - while (!(pbufT = malloc(bufsize))) { + while (!(pbufT = calloc(1, bufsize))) { bufsize >>= 1; if (bufsize == 4) { pbufT = tmpbuf; @@ -141,7 +141,7 @@ CopySwap16Write(ClientPtr pClient, int size, short *pbuf) short tmpbuf[2]; /* Allocate as big a buffer as we can... */ - while (!(pbufT = malloc(bufsize))) { + while (!(pbufT = calloc(1, bufsize))) { bufsize >>= 1; if (bufsize == 4) { pbufT = tmpbuf; @@ -1130,9 +1130,7 @@ SwapConnSetupInfo(char *pInfo, char *pInfoT) void _X_COLD WriteSConnectionInfo(ClientPtr pClient, unsigned long size, char *pInfo) { - char *pInfoTBase; - - pInfoTBase = malloc(size); + char *pInfoTBase = calloc(1, size); if (!pInfoTBase) { pClient->noClientException = -1; return; diff --git a/dix/window.c b/dix/window.c index 672593512..a9e084c04 100644 --- a/dix/window.c +++ b/dix/window.c @@ -592,7 +592,7 @@ CreateRootWindow(ScreenPtr pScreen) pWin->parent = NullWindow; SetWindowToDefaults(pWin); - pWin->optional = malloc(sizeof(WindowOptRec)); + pWin->optional = calloc(1, sizeof(WindowOptRec)); if (!pWin->optional) return FALSE; @@ -3216,7 +3216,6 @@ TileScreenSaver(ScreenPtr pScreen, int kind) Mask mask; WindowPtr pWin; CursorMetricRec cm; - unsigned char *srcbits, *mskbits; CursorPtr cursor; XID cursorID = 0; int attri; @@ -3254,8 +3253,8 @@ TileScreenSaver(ScreenPtr pScreen, int kind) cm.height = 16; cm.xhot = 8; cm.yhot = 8; - srcbits = malloc(BitmapBytePad(32) * 16); - mskbits = malloc(BitmapBytePad(32) * 16); + unsigned char *srcbits = calloc(16, BitmapBytePad(32)); + unsigned char *mskbits = calloc(16, BitmapBytePad(32)); if (!srcbits || !mskbits) { free(srcbits); free(mskbits); @@ -3395,12 +3394,12 @@ CheckWindowOptionalNeed(WindowPtr w) Bool MakeWindowOptional(WindowPtr pWin) { - WindowOptPtr optional; WindowOptPtr parentOptional; if (pWin->optional) return TRUE; - optional = malloc(sizeof(WindowOptRec)); + + WindowOptPtr optional = calloc(1, sizeof(WindowOptRec)); if (!optional) return FALSE; optional->dontPropagateMask = DontPropagateMasks[pWin->dontPropagate]; @@ -3491,12 +3490,11 @@ ChangeWindowDeviceCursor(WindowPtr pWin, DeviceIntPtr pDev, CursorPtr pCursor) } else { /* no device cursor yet */ - DevCursNodePtr pNewNode; if (!pCursor) return Success; - pNewNode = malloc(sizeof(DevCursNodeRec)); + DevCursNodePtr pNewNode = calloc(1, sizeof(DevCursNodeRec)); pNewNode->dev = pDev; pNewNode->next = pWin->optional->deviceCursors; pWin->optional->deviceCursors = pNewNode;