[PATCH 02/19] Use calloc to zero fill buffers being allocated for replies & events

Alan Coopersmith alan.coopersmith at oracle.com
Sun Jun 24 10:25:09 PDT 2012


Ensures padding bytes are zero-filled

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 Xext/sync.c     |    2 +-
 mi/miexpose.c   |    2 +-
 randr/rrcrtc.c  |    2 +-
 render/render.c |    4 ++--
 xfixes/cursor.c |    7 ++++---
 xfixes/region.c |    3 ++-
 6 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/Xext/sync.c b/Xext/sync.c
index 532bbf9..45aeefc 100644
--- a/Xext/sync.c
+++ b/Xext/sync.c
@@ -474,7 +474,7 @@ SyncSendCounterNotifyEvents(ClientPtr client, SyncAwait ** ppAwait,
 
     if (client->clientGone)
         return;
-    pev = pEvents = malloc(num_events * sizeof(xSyncCounterNotifyEvent));
+    pev = pEvents = calloc(num_events, sizeof(xSyncCounterNotifyEvent));
     if (!pEvents)
         return;
     UpdateCurrentTime();
diff --git a/mi/miexpose.c b/mi/miexpose.c
index dbb29ca..2dc465d 100644
--- a/mi/miexpose.c
+++ b/mi/miexpose.c
@@ -327,7 +327,7 @@ miSendGraphicsExpose(ClientPtr client, RegionPtr pRgn, XID drawable,
 
         numRects = RegionNumRects(pRgn);
         pBox = RegionRects(pRgn);
-        if (!(pEvent = malloc(numRects * sizeof(xEvent))))
+        if (!(pEvent = calloc(numRects, sizeof(xEvent))))
             return;
         pe = pEvent;
 
diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
index f21ef51..b31f389 100644
--- a/randr/rrcrtc.c
+++ b/randr/rrcrtc.c
@@ -1344,7 +1344,7 @@ ProcRRGetCrtcTransform(ClientPtr client)
     nextra = (transform_filter_length(pending) +
               transform_filter_length(current));
 
-    reply = malloc(sizeof(xRRGetCrtcTransformReply) + nextra);
+    reply = calloc(1, sizeof(xRRGetCrtcTransformReply) + nextra);
     if (!reply)
         return BadAlloc;
 
diff --git a/render/render.c b/render/render.c
index be7d21e..3bf0702 100644
--- a/render/render.c
+++ b/render/render.c
@@ -531,7 +531,7 @@ ProcRenderQueryPictIndexValues(ClientPtr client)
     num = pFormat->index.nvalues;
     rlength = (sizeof(xRenderQueryPictIndexValuesReply) +
                num * sizeof(xIndexValue));
-    reply = (xRenderQueryPictIndexValuesReply *) malloc(rlength);
+    reply = (xRenderQueryPictIndexValuesReply *) calloc(1, rlength);
     if (!reply)
         return BadAlloc;
 
@@ -1688,7 +1688,7 @@ ProcRenderQueryFilters(ClientPtr client)
     }
     len = ((nnames + 1) >> 1) + bytes_to_int32(nbytesName);
     total_bytes = sizeof(xRenderQueryFiltersReply) + (len << 2);
-    reply = (xRenderQueryFiltersReply *) malloc(total_bytes);
+    reply = (xRenderQueryFiltersReply *) calloc(1, total_bytes);
     if (!reply)
         return BadAlloc;
     aliases = (INT16 *) (reply + 1);
diff --git a/xfixes/cursor.c b/xfixes/cursor.c
index 79530f9..402456d 100644
--- a/xfixes/cursor.c
+++ b/xfixes/cursor.c
@@ -380,7 +380,8 @@ ProcXFixesGetCursorImage(ClientPtr client)
     width = pCursor->bits->width;
     height = pCursor->bits->height;
     npixels = width * height;
-    rep = malloc(sizeof(xXFixesGetCursorImageReply) + npixels * sizeof(CARD32));
+    rep = calloc(sizeof(xXFixesGetCursorImageReply) + npixels * sizeof(CARD32),
+                 1);
     if (!rep)
         return BadAlloc;
 
@@ -529,8 +530,8 @@ ProcXFixesGetCursorImageAndName(ClientPtr client)
     name = pCursor->name ? NameForAtom(pCursor->name) : "";
     nbytes = strlen(name);
     nbytesRound = pad_to_int32(nbytes);
-    rep = malloc(sizeof(xXFixesGetCursorImageAndNameReply) +
-                 npixels * sizeof(CARD32) + nbytesRound);
+    rep = calloc(sizeof(xXFixesGetCursorImageAndNameReply) +
+                 npixels * sizeof(CARD32) + nbytesRound, 1);
     if (!rep)
         return BadAlloc;
 
diff --git a/xfixes/region.c b/xfixes/region.c
index 89675e5..0e9ca44 100644
--- a/xfixes/region.c
+++ b/xfixes/region.c
@@ -557,7 +557,8 @@ ProcXFixesFetchRegion(ClientPtr client)
     pBox = RegionRects(pRegion);
     nBox = RegionNumRects(pRegion);
 
-    reply = malloc(sizeof(xXFixesFetchRegionReply) + nBox * sizeof(xRectangle));
+    reply = calloc(sizeof(xXFixesFetchRegionReply) + nBox * sizeof(xRectangle),
+                   1);
     if (!reply)
         return BadAlloc;
     reply->type = X_Reply;
-- 
1.7.9.2



More information about the xorg-devel mailing list