svn commit: trunk/busybox: coreutils e2fsprogs findutils include li etc...

landley at busybox.net landley at busybox.net
Thu Aug 3 20:07:37 UTC 2006


Author: landley
Date: 2006-08-03 13:07:35 -0700 (Thu, 03 Aug 2006)
New Revision: 15771

Log:
Remove xcalloc() and convert its callers to xzalloc().  About half of them
were using "1" as one of the arguments anyway, and as for the rest a multiply
and a push isn't noticeably bigger than pushing two arguments on the stack.


Modified:
   trunk/busybox/coreutils/cut.c
   trunk/busybox/coreutils/ls.c
   trunk/busybox/coreutils/sort.c
   trunk/busybox/e2fsprogs/fsck.c
   trunk/busybox/e2fsprogs/mke2fs.c
   trunk/busybox/findutils/grep.c
   trunk/busybox/findutils/xargs.c
   trunk/busybox/include/libbb.h
   trunk/busybox/libbb/xfuncs.c
   trunk/busybox/modutils/insmod.c
   trunk/busybox/modutils/modprobe.c
   trunk/busybox/networking/httpd.c
   trunk/busybox/networking/traceroute.c
   trunk/busybox/shell/cmdedit.c
   trunk/busybox/util-linux/fdisk.c


Changeset:
Modified: trunk/busybox/coreutils/cut.c
===================================================================
--- trunk/busybox/coreutils/cut.c	2006-08-03 17:58:17 UTC (rev 15770)
+++ trunk/busybox/coreutils/cut.c	2006-08-03 20:07:35 UTC (rev 15771)
@@ -135,7 +135,7 @@
 {
 	int c, l;
 	/* set up a list so we can keep track of what's been printed */
-	char *printed = xcalloc(strlen(line), sizeof(char));
+	char *printed = xzalloc(strlen(line));
 
 	/* print the chars specified in each cut list */
 	for (c = 0; c < nlists; c++) {
@@ -172,7 +172,7 @@
 	}
 
 	/* set up a list so we can keep track of what's been printed */
-	printed = xcalloc(strlen(line), sizeof(char));
+	printed = xzalloc(strlen(line));
 
 	/* process each list on this line, for as long as we've got a line to process */
 	for (c = 0; c < nlists && line; c++) {

Modified: trunk/busybox/coreutils/ls.c
===================================================================
--- trunk/busybox/coreutils/ls.c	2006-08-03 17:58:17 UTC (rev 15770)
+++ trunk/busybox/coreutils/ls.c	2006-08-03 20:07:35 UTC (rev 15771)
@@ -300,7 +300,7 @@
 	if (num < 1)
 		return (NULL);
 
-	p = (struct dnode **) xcalloc((size_t) num, (size_t) (sizeof(struct dnode *)));
+	p = (struct dnode **) xzalloc(num * sizeof(struct dnode *));
 	return (p);
 }
 

Modified: trunk/busybox/coreutils/sort.c
===================================================================
--- trunk/busybox/coreutils/sort.c	2006-08-03 17:58:17 UTC (rev 15770)
+++ trunk/busybox/coreutils/sort.c	2006-08-03 20:07:35 UTC (rev 15771)
@@ -120,7 +120,7 @@
 {
 	struct sort_key **pkey=&key_list;
 	while(*pkey) pkey=&((*pkey)->next_key);
-	return *pkey=xcalloc(1,sizeof(struct sort_key));
+	return *pkey = xzalloc(sizeof(struct sort_key));
 }
 
 #define GET_LINE(fp) (global_flags&FLAG_z) ? bb_get_chunk_from_file(fp,NULL) \

Modified: trunk/busybox/e2fsprogs/fsck.c
===================================================================
--- trunk/busybox/e2fsprogs/fsck.c	2006-08-03 17:58:17 UTC (rev 15770)
+++ trunk/busybox/e2fsprogs/fsck.c	2006-08-03 20:07:35 UTC (rev 15771)
@@ -877,8 +877,8 @@
 		}
 	}
 
-	cmp->list = xcalloc(num, sizeof(char *));
-	cmp->type = xcalloc(num, sizeof(int));
+	cmp->list = xzalloc(num * sizeof(char *));
+	cmp->type = xzalloc(num * sizeof(int));
 	cmp->negate = 0;
 
 	if (!fs_type)

Modified: trunk/busybox/e2fsprogs/mke2fs.c
===================================================================
--- trunk/busybox/e2fsprogs/mke2fs.c	2006-08-03 17:58:17 UTC (rev 15770)
+++ trunk/busybox/e2fsprogs/mke2fs.c	2006-08-03 20:07:35 UTC (rev 15771)
@@ -401,7 +401,7 @@
 	}
 	/* Allocate the zeroizing buffer if necessary */
 	if (!buf) {
-		buf = xcalloc(fs->blocksize, STRIDE_LENGTH);
+		buf = xzalloc(fs->blocksize * STRIDE_LENGTH);
 	}
 	/* OK, do the write loop */
 	next_update = 0;

Modified: trunk/busybox/findutils/grep.c
===================================================================
--- trunk/busybox/findutils/grep.c	2006-08-03 17:58:17 UTC (rev 15770)
+++ trunk/busybox/findutils/grep.c	2006-08-03 20:07:35 UTC (rev 15771)
@@ -321,7 +321,7 @@
 		lines_before = 0;
 		lines_after = 0;
 	} else if(lines_before > 0)
-		before_buf = (char **)xcalloc(lines_before, sizeof(char *));
+		before_buf = (char **)xzalloc(lines_before * sizeof(char *));
   }
 #else
 	/* with auto sanity checks */

Modified: trunk/busybox/findutils/xargs.c
===================================================================
--- trunk/busybox/findutils/xargs.c	2006-08-03 17:58:17 UTC (rev 15770)
+++ trunk/busybox/findutils/xargs.c	2006-08-03 20:07:35 UTC (rev 15771)
@@ -503,7 +503,7 @@
 
 		/* allocating pointers for execvp:
 		   a*arg, n*arg from stdin, NULL */
-		args = xcalloc(n + a + 1, sizeof(char *));
+		args = xzalloc((n + a + 1) * sizeof(char *));
 
 		/* Store the command to be executed
 		   (taken from the command line) */

Modified: trunk/busybox/include/libbb.h
===================================================================
--- trunk/busybox/include/libbb.h	2006-08-03 17:58:17 UTC (rev 15770)
+++ trunk/busybox/include/libbb.h	2006-08-03 20:07:35 UTC (rev 15771)
@@ -230,7 +230,6 @@
 extern void *xmalloc(size_t size);
 extern void *xrealloc(void *old, size_t size);
 extern void *xzalloc(size_t size);
-extern void *xcalloc(size_t nmemb, size_t size);
 
 extern char *xstrdup (const char *s);
 extern char *xstrndup (const char *s, int n);

Modified: trunk/busybox/libbb/xfuncs.c
===================================================================
--- trunk/busybox/libbb/xfuncs.c	2006-08-03 17:58:17 UTC (rev 15770)
+++ trunk/busybox/libbb/xfuncs.c	2006-08-03 20:07:35 UTC (rev 15771)
@@ -41,15 +41,6 @@
 }
 #endif
 
-#ifdef L_xcalloc
-void *xcalloc(size_t nmemb, size_t size)
-{
-	void *ptr = calloc(nmemb, size);
-	if (ptr == NULL && nmemb != 0 && size != 0)
-		bb_error_msg_and_die(bb_msg_memory_exhausted);
-	return ptr;
-}
-#endif
 #endif /* DMALLOC */
 
 #ifdef L_xstrdup

Modified: trunk/busybox/modutils/insmod.c
===================================================================
--- trunk/busybox/modutils/insmod.c	2006-08-03 17:58:17 UTC (rev 15770)
+++ trunk/busybox/modutils/insmod.c	2006-08-03 20:07:35 UTC (rev 15771)
@@ -3490,7 +3490,7 @@
 
 					/* Allocate space for a table of local symbols.  */
 					j = f->local_symtab_size = sec->header.sh_info;
-					f->local_symtab = xcalloc(j, sizeof(struct obj_symbol *));
+					f->local_symtab = xzalloc(j * sizeof(struct obj_symbol *));
 
 					/* Insert all symbols into the hash table.  */
 					for (j = 1, ++sym; j < nsym; ++j, ++sym) {

Modified: trunk/busybox/modutils/modprobe.c
===================================================================
--- trunk/busybox/modutils/modprobe.c	2006-08-03 17:58:17 UTC (rev 15770)
+++ trunk/busybox/modutils/modprobe.c	2006-08-03 20:07:35 UTC (rev 15771)
@@ -294,10 +294,10 @@
 				if ( parse_tag_value ( buffer + 6, &alias, &mod )) {
 					/* handle alias as a module dependent on the aliased module */
 					if ( !*current ) {
-						(*first) = (*current) = (struct dep_t *) xcalloc ( 1, sizeof ( struct dep_t ));
+						(*first) = (*current) = (struct dep_t *) xzalloc (sizeof ( struct dep_t ));
 					}
 					else {
-						(*current)-> m_next = (struct dep_t *) xcalloc ( 1, sizeof ( struct dep_t ));
+						(*current)-> m_next = (struct dep_t *) xzalloc (sizeof ( struct dep_t ));
 						(*current) = (*current)-> m_next;
 					}
 					(*current)-> m_name  = xstrdup ( alias );

Modified: trunk/busybox/networking/httpd.c
===================================================================
--- trunk/busybox/networking/httpd.c	2006-08-03 17:58:17 UTC (rev 15770)
+++ trunk/busybox/networking/httpd.c	2006-08-03 20:07:35 UTC (rev 15771)
@@ -1929,7 +1929,7 @@
 
   USE_FEATURE_HTTPD_AUTH_MD5(const char *pass;)
 
-  config = xcalloc(1, sizeof(*config));
+  config = xzalloc(sizeof(*config));
 #ifdef CONFIG_FEATURE_HTTPD_BASIC_AUTH
   config->realm = "Web Server Authentication";
 #endif

Modified: trunk/busybox/networking/traceroute.c
===================================================================
--- trunk/busybox/networking/traceroute.c	2006-08-03 17:58:17 UTC (rev 15770)
+++ trunk/busybox/networking/traceroute.c	2006-08-03 20:07:35 UTC (rev 15771)
@@ -375,7 +375,7 @@
 	ifend = (struct ifreq *)((char *)ibuf + ifc.ifc_len);
 
 	nipaddr = 1 + (ifc.ifc_len / sizeof(struct ifreq));
-	st_ifaddrlist = xcalloc(nipaddr, sizeof(struct IFADDRLIST));
+	st_ifaddrlist = xzalloc(nipaddr * sizeof(struct IFADDRLIST));
 	al = st_ifaddrlist;
 	nipaddr = 0;
 
@@ -872,12 +872,12 @@
 	char **p;
 	u_int32_t addr, *ap;
 
-	hi = xcalloc(1, sizeof(*hi));
+	hi = xzalloc(sizeof(*hi));
 	addr = inet_addr(host);
 	if ((int32_t)addr != -1) {
 		hi->name = xstrdup(host);
 		hi->n = 1;
-		hi->addrs = xcalloc(1, sizeof(hi->addrs[0]));
+		hi->addrs = xzalloc(sizeof(hi->addrs[0]));
 		hi->addrs[0] = addr;
 		return hi;
 	}
@@ -889,7 +889,7 @@
 	for (n = 0, p = hp->h_addr_list; *p != NULL; ++n, ++p)
 		continue;
 	hi->n = n;
-	hi->addrs = xcalloc(n, sizeof(hi->addrs[0]));
+	hi->addrs = xzalloc(n * sizeof(hi->addrs[0]));
 	for (ap = hi->addrs, p = hp->h_addr_list; *p != NULL; ++ap, ++p)
 		memcpy(ap, *p, sizeof(*ap));
 	return hi;
@@ -1161,7 +1161,7 @@
 	xsetgid(getgid());
 	xsetuid(getuid());
 
-	outip = (struct ip *)xcalloc(1, (unsigned)packlen);
+	outip = (struct ip *)xzalloc(packlen);
 
 	outip->ip_v = IPVERSION;
 	if (tos_str)

Modified: trunk/busybox/shell/cmdedit.c
===================================================================
--- trunk/busybox/shell/cmdedit.c	2006-08-03 17:58:17 UTC (rev 15770)
+++ trunk/busybox/shell/cmdedit.c	2006-08-03 20:07:35 UTC (rev 15771)
@@ -311,7 +311,7 @@
 	int prmt_len = 0;
 	size_t cur_prmt_len = 0;
 	char  flg_not_length = '[';
-	char *prmt_mem_ptr = xcalloc(1, 1);
+	char *prmt_mem_ptr = xzalloc(1);
 	char *pwd_buf = xgetcwd(0);
 	char  buf2[PATH_MAX + 1];
 	char  buf[2];
@@ -344,7 +344,7 @@
 			  case 'h':
 				pbuf = hostname_buf;
 				if (pbuf == 0) {
-					pbuf = xcalloc(256, 1);
+					pbuf = xzalloc(256);
 					if (gethostname(pbuf, 255) < 0) {
 						strcpy(pbuf, "?");
 					} else {

Modified: trunk/busybox/util-linux/fdisk.c
===================================================================
--- trunk/busybox/util-linux/fdisk.c	2006-08-03 17:58:17 UTC (rev 15770)
+++ trunk/busybox/util-linux/fdisk.c	2006-08-03 20:07:35 UTC (rev 15771)
@@ -5162,7 +5162,7 @@
 		ext_index = n;
 		pen->ext_pointer = p;
 		pe4->offset = extended_offset = start;
-		pe4->sectorbuffer = xcalloc(1, sector_size);
+		pe4->sectorbuffer = xzalloc(sector_size);
 		pe4->part_table = pt_offset(pe4->sectorbuffer, 0);
 		pe4->ext_pointer = pe4->part_table + 1;
 		pe4->changed = 1;
@@ -5176,7 +5176,7 @@
 	if (partitions > 5 || ptes[4].part_table->sys_ind) {
 		struct pte *pe = &ptes[partitions];
 
-		pe->sectorbuffer = xcalloc(1, sector_size);
+		pe->sectorbuffer = xzalloc(sector_size);
 		pe->part_table = pt_offset(pe->sectorbuffer, 0);
 		pe->ext_pointer = pe->part_table + 1;
 		pe->offset = 0;




More information about the busybox-cvs mailing list