[PATCH:makedepend 3/4] Remove unnecessary casts from malloc/realloc calls

Alan Coopersmith alan.coopersmith at oracle.com
Sun Jan 6 13:04:00 PST 2013


Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 include.c |   10 ++++------
 main.c    |   10 +++++-----
 parse.c   |   11 ++++-------
 3 files changed, 13 insertions(+), 18 deletions(-)

diff --git a/include.c b/include.c
index 4455005..8eb6a52 100644
--- a/include.c
+++ b/include.c
@@ -178,10 +178,8 @@ included_by(struct inclist *ip, struct inclist *newfile)
 	 * If it is already on the list, don't stick it on again.
 	 */
 	if (ip->i_list == NULL) {
-		ip->i_list = (struct inclist **)
-			malloc(sizeof(struct inclist *) * ++ip->i_listlen);
-		ip->i_merged = (boolean *)
-		    malloc(sizeof(boolean) * ip->i_listlen);
+		ip->i_list = malloc(sizeof(struct inclist *) * ++ip->i_listlen);
+		ip->i_merged = malloc(sizeof(boolean) * ip->i_listlen);
 	} else {
 		for (i=0; i<ip->i_listlen; i++)
 			if (ip->i_list[ i ] == newfile) {
@@ -205,9 +203,9 @@ included_by(struct inclist *ip, struct inclist *newfile)
 			    }
 			    return;
 			}
-		ip->i_list = (struct inclist **) realloc(ip->i_list,
+		ip->i_list = realloc(ip->i_list,
 			sizeof(struct inclist *) * ++ip->i_listlen);
-		ip->i_merged = (boolean *)
+		ip->i_merged =
 		    realloc(ip->i_merged, sizeof(boolean) * ip->i_listlen);
 	}
 	ip->i_list[ ip->i_listlen-1 ] = newfile;
diff --git a/main.c b/main.c
index 91c4792..12efb46 100644
--- a/main.c
+++ b/main.c
@@ -187,7 +187,7 @@ main(int argc, char *argv[])
 	    if ((afd = open(argv[1]+1, O_RDONLY)) < 0)
 		fatalerr("cannot open \"%s\"\n", argv[1]+1);
 	    fstat(afd, &ast);
-	    args = (char *)malloc(ast.st_size + 1);
+	    args = malloc(ast.st_size + 1);
 	    if ((ast.st_size = read(afd, args, ast.st_size)) < 0)
 		fatalerr("failed to read %s\n", argv[1]+1);
 	    args[ast.st_size] = '\0';
@@ -215,7 +215,7 @@ main(int argc, char *argv[])
 	    }
 	    if (p[-1])
 		nargc++;
-	    nargv = (char **)malloc(nargc * sizeof(char *));
+	    nargv = malloc(nargc * sizeof(char *));
 	    nargv[0] = argv[0];
 	    argc = 1;
 	    for (p = args; argc < nargc; p += strlen(p) + 1)
@@ -503,16 +503,16 @@ getfile(const char *file)
 	struct filepointer	*content;
 	struct stat	st;
 
-	content = (struct filepointer *)malloc(sizeof(struct filepointer));
+	content = malloc(sizeof(struct filepointer));
 	content->f_name = file;
 	if ((fd = open(file, O_RDONLY)) < 0) {
 		warning("cannot open \"%s\"\n", file);
-		content->f_p = content->f_base = content->f_end = (char *)malloc(1);
+		content->f_p = content->f_base = content->f_end = malloc(1);
 		*content->f_p = '\0';
 		return(content);
 	}
 	fstat(fd, &st);
-	content->f_base = (char *)malloc(st.st_size+1);
+	content->f_base = malloc(st.st_size+1);
 	if (content->f_base == NULL)
 		fatalerr("cannot allocate mem\n");
 	if ((st.st_size = read(fd, content->f_base, st.st_size)) < 0)
diff --git a/parse.c b/parse.c
index c7aad8c..2d7c95a 100644
--- a/parse.c
+++ b/parse.c
@@ -322,13 +322,11 @@ define2(const char *name, const char *val, struct inclist *file)
     /* Make space if it's needed */
     if (file->i_defs == NULL)
     {
-	file->i_defs = (struct symtab **)
-			malloc(sizeof (struct symtab*) * SYMTABINC);
+	file->i_defs = malloc(sizeof (struct symtab*) * SYMTABINC);
 	file->i_ndefs = 0;
     }
     else if (!(file->i_ndefs % SYMTABINC))
-	file->i_defs = (struct symtab **)
-			realloc(file->i_defs,
+	file->i_defs = realloc(file->i_defs,
 			   sizeof(struct symtab*)*(file->i_ndefs+SYMTABINC));
 
     if (file->i_defs == NULL)
@@ -387,7 +385,7 @@ define2(const char *name, const char *val, struct inclist *file)
 	*sp = sp[-1];
 	sp--;
     }
-    stab = (struct symtab *) malloc(sizeof (struct symtab));
+    stab = malloc(sizeof (struct symtab));
     if (stab == NULL)
 	fatalerr("malloc()/realloc() failure in insert_defn()\n");
 
@@ -492,8 +490,7 @@ merge2defines(struct inclist *file1, struct inclist *file2)
                 {
                 	/* make sure deflen % SYMTABINC == 0 is still true */
                 	deflen += (SYMTABINC - deflen % SYMTABINC) % SYMTABINC;
-                	i_defs=(struct symtab**)
-			    malloc(deflen*sizeof(struct symtab*));
+			i_defs = malloc(deflen*sizeof(struct symtab*));
                 	if (i_defs==NULL) return 0;
         	}
 
-- 
1.7.9.2



More information about the xorg-devel mailing list