Commit c81a4578 authored by Ulrich Sibiller's avatar Ulrich Sibiller

Use calloc to zero fill buffers being allocated for replies & events

commit cdf5bcd420e5bcf4a4a24a275d3133a4e16ce41e Author: Alan Coopersmith <alan.coopersmith@oracle.com> Date: Mon Jul 9 19:12:42 2012 -0700 Use calloc to zero fill buffers being allocated for replies & events Ensures padding bytes are zero-filled Signed-off-by: 's avatarAlan Coopersmith <alan.coopersmith@oracle.com> Reviewed-by: 's avatarKeith Packard <keithp@keithp.com> Tested-by: 's avatarDaniel Stone <daniel@fooishbar.org> Attributes ArcticaProject/nx-libs#382
parent a70e36c8
...@@ -2084,7 +2084,7 @@ int __glXQueryExtensionsString(__GLXclientState *cl, GLbyte *pc) ...@@ -2084,7 +2084,7 @@ int __glXQueryExtensionsString(__GLXclientState *cl, GLbyte *pc)
reply.n = n; reply.n = n;
/* Allocate buffer to make sure it's a multiple of 4 bytes big.*/ /* Allocate buffer to make sure it's a multiple of 4 bytes big.*/
buf = (char *) malloc(length << 2); buf = calloc(length, 4);
if (buf == NULL) if (buf == NULL)
return BadAlloc; return BadAlloc;
memcpy(buf, ptr, n); memcpy(buf, ptr, n);
...@@ -2141,7 +2141,7 @@ int __glXQueryServerString(__GLXclientState *cl, GLbyte *pc) ...@@ -2141,7 +2141,7 @@ int __glXQueryServerString(__GLXclientState *cl, GLbyte *pc)
reply.length = length; reply.length = length;
reply.n = n; reply.n = n;
if ((buf = (char *) malloc(length << 2)) == NULL) { if ((buf = calloc(length, 4)) == NULL) {
return BadAlloc; return BadAlloc;
} }
memcpy(buf, ptr, n); memcpy(buf, ptr, n);
......
...@@ -590,7 +590,7 @@ SyncSendCounterNotifyEvents(client, ppAwait, num_events) ...@@ -590,7 +590,7 @@ SyncSendCounterNotifyEvents(client, ppAwait, num_events)
if (client->clientGone) if (client->clientGone)
return; return;
pev = pEvents = (xSyncCounterNotifyEvent *) pev = pEvents = (xSyncCounterNotifyEvent *)
malloc(num_events * sizeof(xSyncCounterNotifyEvent)); calloc(num_events, sizeof(xSyncCounterNotifyEvent));
if (!pEvents) if (!pEvents)
return; return;
UpdateCurrentTime(); UpdateCurrentTime();
......
...@@ -580,7 +580,7 @@ ProcRenderQueryPictIndexValues (ClientPtr client) ...@@ -580,7 +580,7 @@ ProcRenderQueryPictIndexValues (ClientPtr client)
num = pFormat->index.nvalues; num = pFormat->index.nvalues;
rlength = (sizeof (xRenderQueryPictIndexValuesReply) + rlength = (sizeof (xRenderQueryPictIndexValuesReply) +
num * sizeof(xIndexValue)); num * sizeof(xIndexValue));
reply = (xRenderQueryPictIndexValuesReply *) malloc (rlength); reply = (xRenderQueryPictIndexValuesReply *) calloc (1, rlength);
if (!reply) if (!reply)
return BadAlloc; return BadAlloc;
...@@ -1746,7 +1746,7 @@ ProcRenderQueryFilters (ClientPtr client) ...@@ -1746,7 +1746,7 @@ ProcRenderQueryFilters (ClientPtr client)
} }
len = ((nnames + 1) >> 1) + ((nbytesName + 3) >> 2); len = ((nnames + 1) >> 1) + ((nbytesName + 3) >> 2);
total_bytes = sizeof (xRenderQueryFiltersReply) + (len << 2); total_bytes = sizeof (xRenderQueryFiltersReply) + (len << 2);
reply = (xRenderQueryFiltersReply *) malloc (total_bytes); reply = (xRenderQueryFiltersReply *) calloc (1, total_bytes);
if (!reply) if (!reply)
return BadAlloc; return BadAlloc;
aliases = (INT16 *) (reply + 1); aliases = (INT16 *) (reply + 1);
......
...@@ -364,8 +364,8 @@ ProcXFixesGetCursorImage (ClientPtr client) ...@@ -364,8 +364,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 = malloc (sizeof (xXFixesGetCursorImageReply) + rep = calloc (sizeof (xXFixesGetCursorImageReply) +
npixels * sizeof (CARD32)); npixels * sizeof (CARD32), 1);
if (!rep) if (!rep)
return BadAlloc; return BadAlloc;
...@@ -508,8 +508,8 @@ ProcXFixesGetCursorImageAndName (ClientPtr client) ...@@ -508,8 +508,8 @@ ProcXFixesGetCursorImageAndName (ClientPtr client)
name = pCursor->name ? NameForAtom (pCursor->name) : ""; name = pCursor->name ? NameForAtom (pCursor->name) : "";
nbytes = strlen (name); nbytes = strlen (name);
nbytesRound = (nbytes + 3) & ~3; nbytesRound = (nbytes + 3) & ~3;
rep = malloc (sizeof (xXFixesGetCursorImageAndNameReply) + rep = calloc (sizeof (xXFixesGetCursorImageAndNameReply) +
npixels * sizeof (CARD32) + nbytesRound); npixels * sizeof (CARD32) + nbytesRound, 1);
if (!rep) if (!rep)
return BadAlloc; return BadAlloc;
......
...@@ -570,8 +570,8 @@ ProcXFixesFetchRegion (ClientPtr client) ...@@ -570,8 +570,8 @@ ProcXFixesFetchRegion (ClientPtr client)
pBox = RegionRects (pRegion); pBox = RegionRects (pRegion);
nBox = RegionNumRects (pRegion); nBox = RegionNumRects (pRegion);
reply = malloc (sizeof (xXFixesFetchRegionReply) + reply = calloc (sizeof (xXFixesFetchRegionReply) +
nBox * sizeof (xRectangle)); nBox * sizeof (xRectangle), 1);
if (!reply) if (!reply)
return BadAlloc; return BadAlloc;
reply->type = X_Reply; reply->type = X_Reply;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment