summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2015-03-21 11:07:24 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2015-04-21 16:57:07 -0700
commitf3ba909753cd216fc9eca4618a76cc283ccbf51e (patch)
tree1b48b1c08c341b26ed8d74e339308893021dccbe
parenta28202a148508837911c5932a0d14af4b145bece (diff)
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>
-rw-r--r--Xext/panoramiXprocs.c2
-rw-r--r--Xi/xiquerypointer.c4
-rw-r--r--dix/dispatch.c6
-rw-r--r--dix/glyphcurs.c4
-rw-r--r--hw/xfree86/common/xf86Bus.c2
-rw-r--r--hw/xfree86/common/xf86Config.c2
-rw-r--r--hw/xfree86/common/xf86Configure.c4
7 files changed, 11 insertions, 13 deletions
diff --git a/Xext/panoramiXprocs.c b/Xext/panoramiXprocs.c
index 413a66afb..5291a4a4b 100644
--- a/Xext/panoramiXprocs.c
+++ b/Xext/panoramiXprocs.c
@@ -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,
diff --git a/Xi/xiquerypointer.c b/Xi/xiquerypointer.c
index 7ec0c851d..b9e295815 100644
--- a/Xi/xiquerypointer.c
+++ b/Xi/xiquerypointer.c
@@ -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))
diff --git a/dix/dispatch.c b/dix/dispatch.c
index 17fa75e19..7dcdeab8c 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -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);
diff --git a/dix/glyphcurs.c b/dix/glyphcurs.c
index eca6a4cb8..3ff6ae83e 100644
--- a/dix/glyphcurs.c
+++ b/dix/glyphcurs.c
@@ -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;
diff --git a/hw/xfree86/common/xf86Bus.c b/hw/xfree86/common/xf86Bus.c
index 889294fe7..02f7bf229 100644
--- a/hw/xfree86/common/xf86Bus.c
+++ b/hw/xfree86/common/xf86Bus.c
@@ -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;
}
diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index d42572f38..098d2dd69 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -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
diff --git a/hw/xfree86/common/xf86Configure.c b/hw/xfree86/common/xf86Configure.c
index cc7ff1bb5..7ab378f59 100644
--- a/hw/xfree86/common/xf86Configure.c
+++ b/hw/xfree86/common/xf86Configure.c
@@ -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;