[PATCH:xscope 01/14] Clean up existing malloc calls

Alan Coopersmith alan.coopersmith at oracle.com
Sat Sep 24 08:48:19 PDT 2011


Remove unnecessary casts from (void *)
Ensure return value is checked.

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 common.c  |    4 +++-
 scope.c   |    2 +-
 table11.c |    2 +-
 3 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/common.c b/common.c
index 1d48530..bf64beb 100644
--- a/common.c
+++ b/common.c
@@ -239,7 +239,9 @@ SetUpConnectionSocket(
 	  debug(4,(stderr, 
 	    "Warning: Failed to establish listening connections on some transports\n"));
       } 
-      ListenTransFds = (int *) malloc (ListenTransCount * sizeof (int));
+      ListenTransFds = malloc (ListenTransCount * sizeof (int));
+      if (ListenTransFds == NULL)
+	  panic("Can't allocate memory for ListenTransFds");
 
       for (i = 0; i < ListenTransCount; i++)
       {
diff --git a/scope.c b/scope.c
index 6f9df76..dfe9f00 100644
--- a/scope.c
+++ b/scope.c
@@ -489,7 +489,7 @@ CMDBreak (
 	*minorname = ':'; /* restore string for error message */
 	return CMDSyntax;
       }
-      bp = (BP *) malloc (sizeof (BP));
+      bp = malloc (sizeof (BP));
       bp->number = ++breakPointNumber;
       bp->request = request;
       bp->minorop = minorop;
diff --git a/table11.c b/table11.c
index bfcef73..02dc5fb 100644
--- a/table11.c
+++ b/table11.c
@@ -147,7 +147,7 @@ CreateValueRec (
     int		i;
     
     bucket = &buckets[HASH(key)];
-    value = (ValuePtr) malloc (sizeof (ValueRec) + size * sizeof (unsigned long));
+    value = malloc (sizeof (ValueRec) + (size * sizeof (unsigned long)));
     if (!value)
 	return;
     value->values = (unsigned long *) (value + 1);
-- 
1.7.3.2



More information about the xorg-devel mailing list