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);
|
pitch = PixmapBytePad(stuff->width, drawables[0]->depth);
|
||||||
if (!(data = calloc(1, stuff->height * pitch)))
|
if (!(data = calloc(stuff->height, pitch)))
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
|
|
||||||
XineramaGetImageData(drawables, srcx, srcy,
|
XineramaGetImageData(drawables, srcx, srcy,
|
||||||
|
|
|
@ -152,10 +152,10 @@ ProcXIQueryPointer(ClientPtr client)
|
||||||
rep.buttons_len =
|
rep.buttons_len =
|
||||||
bytes_to_int32(bits_to_bytes(pDev->button->numButtons));
|
bytes_to_int32(bits_to_bytes(pDev->button->numButtons));
|
||||||
rep.length += rep.buttons_len;
|
rep.length += rep.buttons_len;
|
||||||
buttons_size = rep.buttons_len * 4;
|
buttons = calloc(rep.buttons_len, 4);
|
||||||
buttons = calloc(1, buttons_size);
|
|
||||||
if (!buttons)
|
if (!buttons)
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
|
buttons_size = rep.buttons_len * 4;
|
||||||
|
|
||||||
for (i = 1; i < pDev->button->numButtons; i++)
|
for (i = 1; i < pDev->button->numButtons; i++)
|
||||||
if (BitIsOn(pDev->button->down, i))
|
if (BitIsOn(pDev->button->down, i))
|
||||||
|
|
|
@ -2786,7 +2786,7 @@ ProcQueryColors(ClientPtr client)
|
||||||
|
|
||||||
count =
|
count =
|
||||||
bytes_to_int32((client->req_len << 2) - sizeof(xQueryColorsReq));
|
bytes_to_int32((client->req_len << 2) - sizeof(xQueryColorsReq));
|
||||||
prgbs = calloc(1, count * sizeof(xrgb));
|
prgbs = calloc(count, sizeof(xrgb));
|
||||||
if (!prgbs && count)
|
if (!prgbs && count)
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
if ((rc =
|
if ((rc =
|
||||||
|
@ -2908,10 +2908,10 @@ ProcCreateCursor(ClientPtr client)
|
||||||
if (stuff->x > width || stuff->y > height)
|
if (stuff->x > width || stuff->y > height)
|
||||||
return BadMatch;
|
return BadMatch;
|
||||||
|
|
||||||
n = BitmapBytePad(width) * height;
|
srcbits = calloc(BitmapBytePad(width), height);
|
||||||
srcbits = calloc(1, n);
|
|
||||||
if (!srcbits)
|
if (!srcbits)
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
|
n = BitmapBytePad(width) * height;
|
||||||
mskbits = malloc(n);
|
mskbits = malloc(n);
|
||||||
if (!mskbits) {
|
if (!mskbits) {
|
||||||
free(srcbits);
|
free(srcbits);
|
||||||
|
|
|
@ -78,7 +78,6 @@ ServerBitsFromGlyph(FontPtr pfont, unsigned ch, CursorMetricPtr cm,
|
||||||
GCPtr pGC;
|
GCPtr pGC;
|
||||||
xRectangle rect;
|
xRectangle rect;
|
||||||
PixmapPtr ppix;
|
PixmapPtr ppix;
|
||||||
long nby;
|
|
||||||
char *pbits;
|
char *pbits;
|
||||||
ChangeGCVal gcval[3];
|
ChangeGCVal gcval[3];
|
||||||
unsigned char char2b[2];
|
unsigned char char2b[2];
|
||||||
|
@ -88,8 +87,7 @@ ServerBitsFromGlyph(FontPtr pfont, unsigned ch, CursorMetricPtr cm,
|
||||||
char2b[1] = (unsigned char) (ch & 0xff);
|
char2b[1] = (unsigned char) (ch & 0xff);
|
||||||
|
|
||||||
pScreen = screenInfo.screens[0];
|
pScreen = screenInfo.screens[0];
|
||||||
nby = BitmapBytePad(cm->width) * (long) cm->height;
|
pbits = calloc(BitmapBytePad(cm->width), cm->height);
|
||||||
pbits = calloc(1, nby);
|
|
||||||
if (!pbits)
|
if (!pbits)
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
|
|
||||||
|
|
|
@ -260,7 +260,7 @@ xf86AllocateEntity(void)
|
||||||
sizeof(EntityPtr) * xf86NumEntities);
|
sizeof(EntityPtr) * xf86NumEntities);
|
||||||
xf86Entities[xf86NumEntities - 1] = xnfcalloc(1, sizeof(EntityRec));
|
xf86Entities[xf86NumEntities - 1] = xnfcalloc(1, sizeof(EntityRec));
|
||||||
xf86Entities[xf86NumEntities - 1]->entityPrivates =
|
xf86Entities[xf86NumEntities - 1]->entityPrivates =
|
||||||
xnfcalloc(sizeof(DevUnion) * xf86EntityPrivateCount, 1);
|
xnfcalloc(xf86EntityPrivateCount, sizeof(DevUnion));
|
||||||
return xf86NumEntities - 1;
|
return xf86NumEntities - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1502,7 +1502,7 @@ configLayout(serverLayoutPtr servlayoutp, XF86ConfLayoutPtr conf_layout,
|
||||||
if (!count) /* alloc enough storage even if no screen is specified */
|
if (!count) /* alloc enough storage even if no screen is specified */
|
||||||
count = 1;
|
count = 1;
|
||||||
|
|
||||||
slp = xnfcalloc(1, (count + 1) * sizeof(screenLayoutRec));
|
slp = xnfcalloc((count + 1), sizeof(screenLayoutRec));
|
||||||
slp[count].screen = NULL;
|
slp[count].screen = NULL;
|
||||||
/*
|
/*
|
||||||
* now that we have storage, loop over the list again and fill in our
|
* now that we have storage, loop over the list again and fill in our
|
||||||
|
|
|
@ -645,10 +645,10 @@ DoConfigure(void)
|
||||||
|
|
||||||
xf86DoConfigurePass1 = FALSE;
|
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++) {
|
for (screennum = 0; screennum < nDevToConfig; screennum++) {
|
||||||
int k, l, n, oldNumScreens;
|
int k, l, n, oldNumScreens;
|
||||||
|
|
Loading…
Reference in New Issue