Let calloc handle multiplication
It's going to multiply anyway, so if we have non-constant values, might as well let it do the multiplication instead of adding another multiply, and good versions of calloc will check for & avoid overflow in the process. Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com> Reviewed-by: Matt Turner <mattst88@gmail.com>
This commit is contained in:
parent
a28202a148
commit
f3ba909753
|
@ -1106,7 +1106,7 @@ PanoramiXCopyArea(ClientPtr client)
|
|||
}
|
||||
|
||||
pitch = PixmapBytePad(stuff->width, drawables[0]->depth);
|
||||
if (!(data = calloc(1, stuff->height * pitch)))
|
||||
if (!(data = calloc(stuff->height, pitch)))
|
||||
return BadAlloc;
|
||||
|
||||
XineramaGetImageData(drawables, srcx, srcy,
|
||||
|
|
|
@ -152,10 +152,10 @@ ProcXIQueryPointer(ClientPtr client)
|
|||
rep.buttons_len =
|
||||
bytes_to_int32(bits_to_bytes(pDev->button->numButtons));
|
||||
rep.length += rep.buttons_len;
|
||||
buttons_size = rep.buttons_len * 4;
|
||||
buttons = calloc(1, buttons_size);
|
||||
buttons = calloc(rep.buttons_len, 4);
|
||||
if (!buttons)
|
||||
return BadAlloc;
|
||||
buttons_size = rep.buttons_len * 4;
|
||||
|
||||
for (i = 1; i < pDev->button->numButtons; i++)
|
||||
if (BitIsOn(pDev->button->down, i))
|
||||
|
|
|
@ -2786,7 +2786,7 @@ ProcQueryColors(ClientPtr client)
|
|||
|
||||
count =
|
||||
bytes_to_int32((client->req_len << 2) - sizeof(xQueryColorsReq));
|
||||
prgbs = calloc(1, count * sizeof(xrgb));
|
||||
prgbs = calloc(count, sizeof(xrgb));
|
||||
if (!prgbs && count)
|
||||
return BadAlloc;
|
||||
if ((rc =
|
||||
|
@ -2908,10 +2908,10 @@ ProcCreateCursor(ClientPtr client)
|
|||
if (stuff->x > width || stuff->y > height)
|
||||
return BadMatch;
|
||||
|
||||
n = BitmapBytePad(width) * height;
|
||||
srcbits = calloc(1, n);
|
||||
srcbits = calloc(BitmapBytePad(width), height);
|
||||
if (!srcbits)
|
||||
return BadAlloc;
|
||||
n = BitmapBytePad(width) * height;
|
||||
mskbits = malloc(n);
|
||||
if (!mskbits) {
|
||||
free(srcbits);
|
||||
|
|
|
@ -78,7 +78,6 @@ ServerBitsFromGlyph(FontPtr pfont, unsigned ch, CursorMetricPtr cm,
|
|||
GCPtr pGC;
|
||||
xRectangle rect;
|
||||
PixmapPtr ppix;
|
||||
long nby;
|
||||
char *pbits;
|
||||
ChangeGCVal gcval[3];
|
||||
unsigned char char2b[2];
|
||||
|
@ -88,8 +87,7 @@ ServerBitsFromGlyph(FontPtr pfont, unsigned ch, CursorMetricPtr cm,
|
|||
char2b[1] = (unsigned char) (ch & 0xff);
|
||||
|
||||
pScreen = screenInfo.screens[0];
|
||||
nby = BitmapBytePad(cm->width) * (long) cm->height;
|
||||
pbits = calloc(1, nby);
|
||||
pbits = calloc(BitmapBytePad(cm->width), cm->height);
|
||||
if (!pbits)
|
||||
return BadAlloc;
|
||||
|
||||
|
|
|
@ -260,7 +260,7 @@ xf86AllocateEntity(void)
|
|||
sizeof(EntityPtr) * xf86NumEntities);
|
||||
xf86Entities[xf86NumEntities - 1] = xnfcalloc(1, sizeof(EntityRec));
|
||||
xf86Entities[xf86NumEntities - 1]->entityPrivates =
|
||||
xnfcalloc(sizeof(DevUnion) * xf86EntityPrivateCount, 1);
|
||||
xnfcalloc(xf86EntityPrivateCount, sizeof(DevUnion));
|
||||
return xf86NumEntities - 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -1502,7 +1502,7 @@ configLayout(serverLayoutPtr servlayoutp, XF86ConfLayoutPtr conf_layout,
|
|||
if (!count) /* alloc enough storage even if no screen is specified */
|
||||
count = 1;
|
||||
|
||||
slp = xnfcalloc(1, (count + 1) * sizeof(screenLayoutRec));
|
||||
slp = xnfcalloc((count + 1), sizeof(screenLayoutRec));
|
||||
slp[count].screen = NULL;
|
||||
/*
|
||||
* now that we have storage, loop over the list again and fill in our
|
||||
|
|
|
@ -645,10 +645,10 @@ DoConfigure(void)
|
|||
|
||||
xf86DoConfigurePass1 = FALSE;
|
||||
|
||||
dev2screen = xnfcalloc(1, xf86NumDrivers * sizeof(int));
|
||||
dev2screen = xnfcalloc(xf86NumDrivers, sizeof(int));
|
||||
|
||||
{
|
||||
Bool *driverProbed = xnfcalloc(1, xf86NumDrivers * sizeof(Bool));
|
||||
Bool *driverProbed = xnfcalloc(xf86NumDrivers, sizeof(Bool));
|
||||
|
||||
for (screennum = 0; screennum < nDevToConfig; screennum++) {
|
||||
int k, l, n, oldNumScreens;
|
||||
|
|
Loading…
Reference in New Issue