xfixes: 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
d199dcbe4c
commit
45d7b62d95
|
@ -222,7 +222,7 @@ XFixesSelectCursorInput(ClientPtr pClient, WindowPtr pWindow, CARD32 eventMask)
|
||||||
return Success;
|
return Success;
|
||||||
}
|
}
|
||||||
if (!e) {
|
if (!e) {
|
||||||
e = (CursorEventPtr) malloc(sizeof(CursorEventRec));
|
e = calloc(1, sizeof(CursorEventRec));
|
||||||
if (!e)
|
if (!e)
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
|
|
||||||
|
@ -354,7 +354,6 @@ int
|
||||||
ProcXFixesGetCursorImage(ClientPtr client)
|
ProcXFixesGetCursorImage(ClientPtr client)
|
||||||
{
|
{
|
||||||
/* REQUEST(xXFixesGetCursorImageReq); */
|
/* REQUEST(xXFixesGetCursorImageReq); */
|
||||||
xXFixesGetCursorImageReply *rep;
|
|
||||||
CursorPtr pCursor;
|
CursorPtr pCursor;
|
||||||
CARD32 *image;
|
CARD32 *image;
|
||||||
int npixels, width, height, rc, x, y;
|
int npixels, width, height, rc, x, y;
|
||||||
|
@ -371,7 +370,8 @@ ProcXFixesGetCursorImage(ClientPtr client)
|
||||||
width = pCursor->bits->width;
|
width = pCursor->bits->width;
|
||||||
height = pCursor->bits->height;
|
height = pCursor->bits->height;
|
||||||
npixels = width * height;
|
npixels = width * height;
|
||||||
rep = calloc(1,
|
|
||||||
|
xXFixesGetCursorImageReply *rep = calloc(1,
|
||||||
sizeof(xXFixesGetCursorImageReply) + npixels * sizeof(CARD32));
|
sizeof(xXFixesGetCursorImageReply) + npixels * sizeof(CARD32));
|
||||||
if (!rep)
|
if (!rep)
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
|
@ -494,7 +494,6 @@ int
|
||||||
ProcXFixesGetCursorImageAndName(ClientPtr client)
|
ProcXFixesGetCursorImageAndName(ClientPtr client)
|
||||||
{
|
{
|
||||||
/* REQUEST(xXFixesGetCursorImageAndNameReq); */
|
/* REQUEST(xXFixesGetCursorImageAndNameReq); */
|
||||||
xXFixesGetCursorImageAndNameReply *rep;
|
|
||||||
CursorPtr pCursor;
|
CursorPtr pCursor;
|
||||||
CARD32 *image;
|
CARD32 *image;
|
||||||
int npixels;
|
int npixels;
|
||||||
|
@ -518,7 +517,9 @@ ProcXFixesGetCursorImageAndName(ClientPtr client)
|
||||||
name = pCursor->name ? NameForAtom(pCursor->name) : "";
|
name = pCursor->name ? NameForAtom(pCursor->name) : "";
|
||||||
nbytes = strlen(name);
|
nbytes = strlen(name);
|
||||||
nbytesRound = pad_to_int32(nbytes);
|
nbytesRound = pad_to_int32(nbytes);
|
||||||
rep = calloc(1, sizeof(xXFixesGetCursorImageAndNameReply) +
|
|
||||||
|
xXFixesGetCursorImageAndNameReply *rep = calloc(1,
|
||||||
|
sizeof(xXFixesGetCursorImageAndNameReply) +
|
||||||
npixels * sizeof(CARD32) + nbytesRound);
|
npixels * sizeof(CARD32) + nbytesRound);
|
||||||
if (!rep)
|
if (!rep)
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
|
@ -758,9 +759,7 @@ static int
|
||||||
createCursorHideCount(ClientPtr pClient, ScreenPtr pScreen)
|
createCursorHideCount(ClientPtr pClient, ScreenPtr pScreen)
|
||||||
{
|
{
|
||||||
CursorScreenPtr cs = GetCursorScreen(pScreen);
|
CursorScreenPtr cs = GetCursorScreen(pScreen);
|
||||||
CursorHideCountPtr pChc;
|
CursorHideCountPtr pChc = calloc(1, sizeof(CursorHideCountRec));
|
||||||
|
|
||||||
pChc = (CursorHideCountPtr) malloc(sizeof(CursorHideCountRec));
|
|
||||||
if (pChc == NULL) {
|
if (pChc == NULL) {
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,7 +142,7 @@ XFixesSelectSelectionInput(ClientPtr pClient,
|
||||||
return Success;
|
return Success;
|
||||||
}
|
}
|
||||||
if (!e) {
|
if (!e) {
|
||||||
e = (SelectionEventPtr) malloc(sizeof(SelectionEventRec));
|
e = calloc(1, sizeof(SelectionEventRec));
|
||||||
if (!e)
|
if (!e)
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue