mi: use calloc() instead of malloc()
Using calloc() instead of malloc() as preventive measure, so there never can be any hidden bugs or leaks due uninitialized memory. The extra cost of using this compiler intrinsic should be practically impossible to measure - in many cases a good compiler can even deduce if certain areas really don't need to be zero'd (because they're written to right after allocation) and create more efficient machine code. The code pathes in question are pretty cold anyways, so it's probably not worth even thinking about potential extra runtime costs. Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
parent
55544ff85f
commit
8c05f4db0a
13
mi/miarc.c
13
mi/miarc.c
|
@ -747,13 +747,12 @@ tailX(double K,
|
||||||
static miArcSpanData *
|
static miArcSpanData *
|
||||||
miComputeWideEllipse(int lw, xArc * parc)
|
miComputeWideEllipse(int lw, xArc * parc)
|
||||||
{
|
{
|
||||||
miArcSpanData *spdata = NULL;
|
|
||||||
int k;
|
int k;
|
||||||
|
|
||||||
if (!lw)
|
if (!lw)
|
||||||
lw = 1;
|
lw = 1;
|
||||||
k = (parc->height >> 1) + ((lw - 1) >> 1);
|
k = (parc->height >> 1) + ((lw - 1) >> 1);
|
||||||
spdata = malloc(sizeof(miArcSpanData) + sizeof(miArcSpan) * (k + 2));
|
miArcSpanData *spdata = calloc(1, sizeof(miArcSpanData) + sizeof(miArcSpan) * (k + 2));
|
||||||
if (!spdata)
|
if (!spdata)
|
||||||
return NULL;
|
return NULL;
|
||||||
spdata->spans = (miArcSpan *) (spdata + 1);
|
spdata->spans = (miArcSpan *) (spdata + 1);
|
||||||
|
@ -772,7 +771,6 @@ miFillWideEllipse(DrawablePtr pDraw, GCPtr pGC, xArc * parc)
|
||||||
{
|
{
|
||||||
DDXPointPtr points;
|
DDXPointPtr points;
|
||||||
DDXPointPtr pts;
|
DDXPointPtr pts;
|
||||||
int *widths;
|
|
||||||
int *wids;
|
int *wids;
|
||||||
miArcSpanData *spdata;
|
miArcSpanData *spdata;
|
||||||
miArcSpan *span;
|
miArcSpan *span;
|
||||||
|
@ -781,7 +779,7 @@ miFillWideEllipse(DrawablePtr pDraw, GCPtr pGC, xArc * parc)
|
||||||
|
|
||||||
yorgu = parc->height + pGC->lineWidth;
|
yorgu = parc->height + pGC->lineWidth;
|
||||||
n = (sizeof(int) * 2) * yorgu;
|
n = (sizeof(int) * 2) * yorgu;
|
||||||
widths = malloc(n + (sizeof(DDXPointRec) * 2) * yorgu);
|
int *widths = calloc(1, n + (sizeof(DDXPointRec) * 2) * yorgu);
|
||||||
if (!widths)
|
if (!widths)
|
||||||
return;
|
return;
|
||||||
points = (DDXPointPtr) ((char *) widths + n);
|
points = (DDXPointPtr) ((char *) widths + n);
|
||||||
|
@ -1395,7 +1393,7 @@ miArcJoin(DrawablePtr pDraw, GCPtr pGC, miArcFacePtr pLeft,
|
||||||
arc.height = width;
|
arc.height = width;
|
||||||
arc.angle1 = -miDatan2(corner.y - center.y, corner.x - center.x);
|
arc.angle1 = -miDatan2(corner.y - center.y, corner.x - center.x);
|
||||||
arc.angle2 = a;
|
arc.angle2 = a;
|
||||||
pArcPts = malloc(3 * sizeof(SppPointRec));
|
pArcPts = calloc(3, sizeof(SppPointRec));
|
||||||
if (!pArcPts)
|
if (!pArcPts)
|
||||||
return;
|
return;
|
||||||
pArcPts[0].x = otherCorner.x;
|
pArcPts[0].x = otherCorner.x;
|
||||||
|
@ -1637,7 +1635,7 @@ miDatan2(double dy, double dx)
|
||||||
* This procedure allocates the space necessary to fit the arc points.
|
* This procedure allocates the space necessary to fit the arc points.
|
||||||
* Sometimes it's convenient for those points to be at the end of an existing
|
* Sometimes it's convenient for those points to be at the end of an existing
|
||||||
* array. (For example, if we want to leave a spare point to make sectors
|
* array. (For example, if we want to leave a spare point to make sectors
|
||||||
* instead of segments.) So we pass in the malloc()ed chunk that contains the
|
* instead of segments.) So we pass in the calloc()ed chunk that contains the
|
||||||
* array and an index saying where we should start stashing the points.
|
* array and an index saying where we should start stashing the points.
|
||||||
* If there isn't an array already, we just pass in a null pointer and
|
* If there isn't an array already, we just pass in a null pointer and
|
||||||
* count on realloc() to handle the null pointer correctly.
|
* count on realloc() to handle the null pointer correctly.
|
||||||
|
@ -3037,11 +3035,10 @@ static struct finalSpanChunk *chunks;
|
||||||
static struct finalSpan *
|
static struct finalSpan *
|
||||||
realAllocSpan(void)
|
realAllocSpan(void)
|
||||||
{
|
{
|
||||||
struct finalSpanChunk *newChunk;
|
|
||||||
struct finalSpan *span;
|
struct finalSpan *span;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
newChunk = malloc(sizeof(struct finalSpanChunk));
|
struct finalSpanChunk *newChunk = calloc(1, sizeof(struct finalSpanChunk));
|
||||||
if (!newChunk)
|
if (!newChunk)
|
||||||
return (struct finalSpan *) NULL;
|
return (struct finalSpan *) NULL;
|
||||||
newChunk->next = chunks;
|
newChunk->next = chunks;
|
||||||
|
|
|
@ -330,9 +330,9 @@ miSetVisualTypesAndMasks(int depth, int visuals, int bitsPerRGB,
|
||||||
int preferredCVC,
|
int preferredCVC,
|
||||||
Pixel redMask, Pixel greenMask, Pixel blueMask)
|
Pixel redMask, Pixel greenMask, Pixel blueMask)
|
||||||
{
|
{
|
||||||
miVisualsPtr new, *prev, v;
|
miVisualsPtr *prev, v;
|
||||||
|
|
||||||
new = malloc(sizeof *new);
|
miVisualsPtr new = calloc(1, sizeof *new);
|
||||||
if (!new)
|
if (!new)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
if (!redMask || !greenMask || !blueMask) {
|
if (!redMask || !greenMask || !blueMask) {
|
||||||
|
|
|
@ -665,7 +665,7 @@ miPolyFillArc(DrawablePtr pDraw, GCPtr pGC, int narcs_all, xArc * parcs)
|
||||||
nspans += (arc->height + 1) >> 1;
|
nspans += (arc->height + 1) >> 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pts = points = malloc (sizeof (DDXPointRec) * nspans +
|
pts = points = calloc(1, sizeof (DDXPointRec) * nspans +
|
||||||
sizeof(int) * nspans);
|
sizeof(int) * nspans);
|
||||||
if (points) {
|
if (points) {
|
||||||
wids = widths = (int *) (points + nspans);
|
wids = widths = (int *) (points + nspans);
|
||||||
|
|
|
@ -124,7 +124,7 @@ miInitOverlay(ScreenPtr pScreen,
|
||||||
if (!dixRegisterPrivateKey(&miOverlayScreenKeyRec, PRIVATE_SCREEN, 0))
|
if (!dixRegisterPrivateKey(&miOverlayScreenKeyRec, PRIVATE_SCREEN, 0))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (!(pScreenPriv = malloc(sizeof(miOverlayScreenRec))))
|
if (!(pScreenPriv = calloc(1, sizeof(miOverlayScreenRec))))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
dixSetPrivate(&pScreen->devPrivates, miOverlayScreenKey, pScreenPriv);
|
dixSetPrivate(&pScreen->devPrivates, miOverlayScreenKey, pScreenPriv);
|
||||||
|
|
|
@ -134,7 +134,7 @@ miPointerInitialize(ScreenPtr pScreen,
|
||||||
if (!dixRegisterPrivateKey(&miPointerPrivKeyRec, PRIVATE_DEVICE, 0))
|
if (!dixRegisterPrivateKey(&miPointerPrivKeyRec, PRIVATE_DEVICE, 0))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
pScreenPriv = malloc(sizeof(miPointerScreenRec));
|
pScreenPriv = calloc(1, sizeof(miPointerScreenRec));
|
||||||
if (!pScreenPriv)
|
if (!pScreenPriv)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
pScreenPriv->spriteFuncs = spriteFuncs;
|
pScreenPriv->spriteFuncs = spriteFuncs;
|
||||||
|
@ -323,11 +323,9 @@ miRecolorCursor(DeviceIntPtr pDev, ScreenPtr pScr,
|
||||||
static Bool
|
static Bool
|
||||||
miPointerDeviceInitialize(DeviceIntPtr pDev, ScreenPtr pScreen)
|
miPointerDeviceInitialize(DeviceIntPtr pDev, ScreenPtr pScreen)
|
||||||
{
|
{
|
||||||
miPointerPtr pPointer;
|
|
||||||
|
|
||||||
SetupScreen(pScreen);
|
SetupScreen(pScreen);
|
||||||
|
|
||||||
pPointer = malloc(sizeof(miPointerRec));
|
miPointerPtr pPointer = calloc(1, sizeof(miPointerRec));
|
||||||
if (!pPointer)
|
if (!pPointer)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
|
|
@ -87,7 +87,7 @@ miInsertEdgeInET(EdgeTable * ET, EdgeTableEntry * ETE, int scanline,
|
||||||
*/
|
*/
|
||||||
if ((!pSLL) || (pSLL->scanline > scanline)) {
|
if ((!pSLL) || (pSLL->scanline > scanline)) {
|
||||||
if (*iSLLBlock > SLLSPERBLOCK - 1) {
|
if (*iSLLBlock > SLLSPERBLOCK - 1) {
|
||||||
tmpSLLBlock = malloc(sizeof(ScanLineListBlock));
|
tmpSLLBlock = calloc(1, sizeof(ScanLineListBlock));
|
||||||
if (!tmpSLLBlock)
|
if (!tmpSLLBlock)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
(*SLLBlock)->next = tmpSLLBlock;
|
(*SLLBlock)->next = tmpSLLBlock;
|
||||||
|
@ -542,7 +542,7 @@ miFillGeneralPoly(DrawablePtr dst, GCPtr pgc, int count, DDXPointPtr ptsIn)
|
||||||
if (count < 3)
|
if (count < 3)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
if (!(pETEs = malloc(sizeof(EdgeTableEntry) * count)))
|
if (!(pETEs = calloc(count, sizeof(EdgeTableEntry))))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
ptsOut = FirstPoint;
|
ptsOut = FirstPoint;
|
||||||
width = FirstWidth;
|
width = FirstWidth;
|
||||||
|
|
|
@ -93,7 +93,6 @@ miPushPixels(GCPtr pGC, PixmapPtr pBitMap, DrawablePtr pDrawable,
|
||||||
int dx, int dy, int xOrg, int yOrg)
|
int dx, int dy, int xOrg, int yOrg)
|
||||||
{
|
{
|
||||||
int h, dxDivPPW, ibEnd;
|
int h, dxDivPPW, ibEnd;
|
||||||
MiBits *pwLineStart;
|
|
||||||
MiBits *pw, *pwEnd;
|
MiBits *pw, *pwEnd;
|
||||||
MiBits msk;
|
MiBits msk;
|
||||||
int ib, w;
|
int ib, w;
|
||||||
|
@ -116,7 +115,7 @@ miPushPixels(GCPtr pGC, PixmapPtr pBitMap, DrawablePtr pDrawable,
|
||||||
startmask = (MiBits) (-1) ^ LONG2CHARSDIFFORDER((MiBits) (-1) >> 1);
|
startmask = (MiBits) (-1) ^ LONG2CHARSDIFFORDER((MiBits) (-1) >> 1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pwLineStart = malloc(BitmapBytePad(dx));
|
MiBits *pwLineStart = calloc(1, BitmapBytePad(dx));
|
||||||
if (!pwLineStart)
|
if (!pwLineStart)
|
||||||
return;
|
return;
|
||||||
ipt = 0;
|
ipt = 0;
|
||||||
|
|
|
@ -192,13 +192,11 @@ miCreateScreenResources(ScreenPtr pScreen)
|
||||||
static Bool
|
static Bool
|
||||||
miScreenDevPrivateInit(ScreenPtr pScreen, int width, void *pbits, int xsize, int ysize)
|
miScreenDevPrivateInit(ScreenPtr pScreen, int width, void *pbits, int xsize, int ysize)
|
||||||
{
|
{
|
||||||
miScreenInitParmsPtr pScrInitParms;
|
|
||||||
|
|
||||||
/* Stash pbits and width in a short-lived miScreenInitParmsRec attached
|
/* Stash pbits and width in a short-lived miScreenInitParmsRec attached
|
||||||
* to the screen, until CreateScreenResources can put them in the
|
* to the screen, until CreateScreenResources can put them in the
|
||||||
* screen pixmap.
|
* screen pixmap.
|
||||||
*/
|
*/
|
||||||
pScrInitParms = malloc(sizeof(miScreenInitParmsRec));
|
miScreenInitParmsPtr pScrInitParms = calloc(1, sizeof(miScreenInitParmsRec));
|
||||||
if (!pScrInitParms)
|
if (!pScrInitParms)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
pScrInitParms->pbits = pbits;
|
pScrInitParms->pbits = pbits;
|
||||||
|
|
|
@ -280,7 +280,6 @@ miSpriteReportDamage(DamagePtr pDamage, RegionPtr pRegion, void *closure)
|
||||||
Bool
|
Bool
|
||||||
miSpriteInitialize(ScreenPtr pScreen, miPointerScreenFuncPtr screenFuncs)
|
miSpriteInitialize(ScreenPtr pScreen, miPointerScreenFuncPtr screenFuncs)
|
||||||
{
|
{
|
||||||
miSpriteScreenPtr pScreenPriv;
|
|
||||||
VisualPtr pVisual;
|
VisualPtr pVisual;
|
||||||
|
|
||||||
if (!DamageSetup(pScreen))
|
if (!DamageSetup(pScreen))
|
||||||
|
@ -293,7 +292,7 @@ miSpriteInitialize(ScreenPtr pScreen, miPointerScreenFuncPtr screenFuncs)
|
||||||
(&miSpriteDevPrivatesKeyRec, PRIVATE_DEVICE, sizeof(miCursorInfoRec)))
|
(&miSpriteDevPrivatesKeyRec, PRIVATE_DEVICE, sizeof(miCursorInfoRec)))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
pScreenPriv = malloc(sizeof(miSpriteScreenRec));
|
miSpriteScreenPtr pScreenPriv = calloc(1, sizeof(miSpriteScreenRec));
|
||||||
if (!pScreenPriv)
|
if (!pScreenPriv)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue