[PATCH:libX11 20/22] Don't cast sizeof() results to unsigned when passing to Xmalloc/Xcalloc

Alan Coopersmith alan.coopersmith at oracle.com
Mon Aug 12 00:04:11 PDT 2013


sizeof() returns size_t, malloc() & calloc() expect sizes in size_t,
don't strip down to unsigned int and re-expand unnecessarily.

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 src/xcms/CCC.c        |    5 ++---
 src/xcms/cmsCmap.c    |    5 ++---
 src/xcms/cmsInt.c     |    4 ++--
 src/xlibi18n/ICWrap.c |    2 +-
 4 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/src/xcms/CCC.c b/src/xcms/CCC.c
index da8b661..de6d631 100644
--- a/src/xcms/CCC.c
+++ b/src/xcms/CCC.c
@@ -111,7 +111,7 @@ XcmsCreateCCC(
     XcmsPerScrnInfo *pNewScrnInfo;
 
     if (pDefaultCCC == NULL ||
-	    !(newccc = Xcalloc(1, (unsigned) sizeof(XcmsCCCRec)))) {
+	    !(newccc = Xcalloc(1, sizeof(XcmsCCCRec)))) {
 	return(NULL);
     }
 
@@ -144,8 +144,7 @@ XcmsCreateCCC(
      * If one exists replace the pPerScrnInfo.
      */
     if ((pIMap = _XcmsGetIntensityMap(dpy, visual)) != NULL) {
-	if (!(pNewScrnInfo =
-		Xcalloc(1, (unsigned) sizeof(XcmsPerScrnInfo)))) {
+	if (!(pNewScrnInfo = Xcalloc(1, sizeof(XcmsPerScrnInfo)))) {
 	    Xfree(newccc);
 	    return(NULL);
 	}
diff --git a/src/xcms/cmsCmap.c b/src/xcms/cmsCmap.c
index 45843e3..8db6ffe 100644
--- a/src/xcms/cmsCmap.c
+++ b/src/xcms/cmsCmap.c
@@ -250,8 +250,7 @@ _XcmsAddCmapRec(
 {
     XcmsCmapRec *pNew;
 
-    if ((pNew = Xcalloc(1, (unsigned) sizeof(XcmsCmapRec)))
-	    == NULL) {
+    if ((pNew = Xcalloc(1, sizeof(XcmsCmapRec))) == NULL) {
 	return((XcmsCmapRec *)NULL);
     }
 
@@ -301,7 +300,7 @@ _XcmsCopyCmapRecAndFree(
 	pRec_copy =_XcmsAddCmapRec(dpy, copy_cmap, pRec_src->windowID,
 		pRec_src->visual);
 	if (pRec_copy != NULL && pRec_src->ccc) {
-	    pRec_copy->ccc = Xcalloc(1, (unsigned) sizeof(XcmsCCCRec));
+	    pRec_copy->ccc = Xcalloc(1, sizeof(XcmsCCCRec));
 	    memcpy((char *)pRec_copy->ccc, (char *)pRec_src->ccc,
 		   sizeof(XcmsCCCRec));
 	}
diff --git a/src/xcms/cmsInt.c b/src/xcms/cmsInt.c
index cefa1e6..f4aef04 100644
--- a/src/xcms/cmsInt.c
+++ b/src/xcms/cmsInt.c
@@ -183,7 +183,7 @@ _XcmsInitDefaultCCCs(
      * Create an array of XcmsCCC structures, one for each screen.
      * They serve as the screen's default CCC.
      */
-    if (!(ccc = Xcalloc((unsigned)nScrn, (unsigned) sizeof(XcmsCCCRec)))) {
+    if (!(ccc = Xcalloc((unsigned)nScrn, sizeof(XcmsCCCRec)))) {
 	return(0);
     }
     dpy->cms.defaultCCCs = (XPointer)ccc;
@@ -322,7 +322,7 @@ _XcmsInitScrnInfo(
 	 * here are referenced by the default CCC.
 	 */
 	if (!(defaultccc->pPerScrnInfo =
-		Xcalloc(1, (unsigned) sizeof(XcmsPerScrnInfo)))) {
+		Xcalloc(1, sizeof(XcmsPerScrnInfo)))) {
 	    return(0);
 	}
 	defaultccc->pPerScrnInfo->state = XcmsInitNone;
diff --git a/src/xlibi18n/ICWrap.c b/src/xlibi18n/ICWrap.c
index 8584e36..dadc8f5 100644
--- a/src/xlibi18n/ICWrap.c
+++ b/src/xlibi18n/ICWrap.c
@@ -128,7 +128,7 @@ _XIMVaToNestedList(va_list var, int max_count, XIMArg **args_return)
 	return;
     }
 
-    args = Xmalloc((unsigned)(max_count + 1) * sizeof(XIMArg));
+    args = Xmalloc(((unsigned)max_count + 1) * sizeof(XIMArg));
     *args_return = args;
     if (!args) return;
 
-- 
1.7.9.2



More information about the xorg-devel mailing list