svn commit: trunk/busybox: editors networking/udhcp

landley at busybox.net landley at busybox.net
Sun May 21 18:30:37 UTC 2006


Author: landley
Date: 2006-05-21 11:30:35 -0700 (Sun, 21 May 2006)
New Revision: 15156

Log:
Minor cleanups: Convert a few calloc() calls to xzalloc, remove unnecessary
memset, collate variable declarations...


Modified:
   trunk/busybox/editors/awk.c
   trunk/busybox/editors/sed.c
   trunk/busybox/networking/udhcp/dhcpd.c
   trunk/busybox/networking/udhcp/script.c


Changeset:
Modified: trunk/busybox/editors/awk.c
===================================================================
--- trunk/busybox/editors/awk.c	2006-05-21 18:28:13 UTC (rev 15155)
+++ trunk/busybox/editors/awk.c	2006-05-21 18:30:35 UTC (rev 15156)
@@ -474,9 +474,9 @@
 {
 	xhash *newhash;
 
-	newhash = (xhash *)xcalloc(1, sizeof(xhash));
+	newhash = (xhash *)xzalloc(sizeof(xhash));
 	newhash->csize = FIRST_PRIME;
-	newhash->items = (hash_item **)xcalloc(newhash->csize, sizeof(hash_item *));
+	newhash->items = (hash_item **)xzalloc(newhash->csize * sizeof(hash_item *));
 
 	return newhash;
 }
@@ -505,7 +505,7 @@
 		return;
 
 	newsize = PRIMES[hash->nprime++];
-	newitems = (hash_item **)xcalloc(newsize, sizeof(hash_item *));
+	newitems = (hash_item **)xzalloc(newsize * sizeof(hash_item *));
 
 	for (i=0; i<hash->csize; i++) {
 		hi = hash->items[i];
@@ -536,7 +536,7 @@
 			hash_rebuild(hash);
 
 		l = strlen(name) + 1;
-		hi = xcalloc(sizeof(hash_item) + l, 1);
+		hi = xzalloc(sizeof(hash_item) + l);
 		memcpy(hi->name, name, l);
 
 		idx = hashidx(name) % hash->csize;
@@ -993,7 +993,7 @@
 {
 	register node *n;
 
-	n = (node *)xcalloc(sizeof(node), 1);
+	n = (node *)xzalloc(sizeof(node));
 	n->info = info;
 	n->lineno = lineno;
 	return n;
@@ -1095,7 +1095,7 @@
 				  case TC_NUMBER:
 				  case TC_STRING:
 					cn->info = OC_VAR;
-					v = cn->l.v = xcalloc(sizeof(var), 1);
+					v = cn->l.v = xzalloc(sizeof(var));
 					if (tc & TC_NUMBER)
 						setvar_i(v, t.number);
 					else
@@ -1104,7 +1104,7 @@
 
 				  case TC_REGEXP:
 					mk_re_node(t.string, cn,
-									(regex_t *)xcalloc(sizeof(regex_t),2));
+									(regex_t *)xzalloc(sizeof(regex_t)*2));
 					break;
 
 				  case TC_FUNCTION:
@@ -1590,7 +1590,7 @@
 		free(v->x.walker);
 
 	v->type |= VF_WALK;
-	w = v->x.walker = (char **)xcalloc(2 + 2*sizeof(char *) + array->glen, 1);
+	w = v->x.walker = (char **)xzalloc(2 + 2*sizeof(char *) + array->glen);
 	*w = *(w+1) = (char *)(w + 2);
 	for (i=0; i<array->csize; i++) {
 		hi = array->items[i];

Modified: trunk/busybox/editors/sed.c
===================================================================
--- trunk/busybox/editors/sed.c	2006-05-21 18:28:13 UTC (rev 15155)
+++ trunk/busybox/editors/sed.c	2006-05-21 18:30:35 UTC (rev 15156)
@@ -449,7 +449,7 @@
 		parse_escapes(match,match,strlen(match),i,i);
 		parse_escapes(replace,replace,strlen(replace),i,i);
 
-		sed_cmd->string = xcalloc(1, (strlen(match) + 1) * 2);
+		sed_cmd->string = xzalloc((strlen(match) + 1) * 2);
 		for (i = 0; match[i] && replace[i]; i++) {
 			sed_cmd->string[i * 2] = match[i];
 			sed_cmd->string[(i * 2) + 1] = replace[i];
@@ -513,7 +513,7 @@
 		 *            part1 part2  part3
 		 */
 
-		sed_cmd = xcalloc(1, sizeof(sed_cmd_t));
+		sed_cmd = xzalloc(sizeof(sed_cmd_t));
 
 		/* first part (if present) is an address: either a '$', a number or a /regex/ */
 		cmdstr += get_address(cmdstr, &sed_cmd->beg_line, &sed_cmd->beg_match);

Modified: trunk/busybox/networking/udhcp/dhcpd.c
===================================================================
--- trunk/busybox/networking/udhcp/dhcpd.c	2006-05-21 18:28:13 UTC (rev 15155)
+++ trunk/busybox/networking/udhcp/dhcpd.c	2006-05-21 18:30:35 UTC (rev 15156)
@@ -52,30 +52,18 @@
 struct server_config_t server_config;
 
 
-#ifdef COMBINED_BINARY
 int udhcpd_main(int argc, char *argv[])
-#else
-int main(int argc, char *argv[])
-#endif
 {
 	fd_set rfds;
 	struct timeval tv;
-	int server_socket = -1;
-	int bytes, retval;
+	int server_socket = -1, bytes, retval, max_sock;
 	struct dhcpMessage packet;
-	uint8_t *state;
-	uint8_t *server_id, *requested;
-	uint32_t server_id_align, requested_align;
-	unsigned long timeout_end;
+	uint8_t *state, *server_id, *requested;
+	uint32_t server_id_align, requested_align, static_lease_ip;
+	unsigned long timeout_end, num_ips;
 	struct option_set *option;
-	struct dhcpOfferedAddr *lease;
-	struct dhcpOfferedAddr static_lease;
-	int max_sock;
-	unsigned long num_ips;
+	struct dhcpOfferedAddr *lease, static_lease;
 
-	uint32_t static_lease_ip;
-
-	memset(&server_config, 0, sizeof(struct server_config_t));
 	read_config(argc < 2 ? DHCPD_CONF_FILE : argv[1]);
 
 	/* Start the log, sanitize fd's, and write a pid file */
@@ -96,7 +84,7 @@
 		server_config.max_leases = num_ips;
 	}
 
-	leases = xcalloc(server_config.max_leases, sizeof(struct dhcpOfferedAddr));
+	leases = xzalloc(server_config.max_leases * sizeof(struct dhcpOfferedAddr));
 	read_leases(server_config.lease_file);
 
 	if (read_interface(server_config.interface, &server_config.ifindex,

Modified: trunk/busybox/networking/udhcp/script.c
===================================================================
--- trunk/busybox/networking/udhcp/script.c	2006-05-21 18:28:13 UTC (rev 15155)
+++ trunk/busybox/networking/udhcp/script.c	2006-05-21 18:30:35 UTC (rev 15156)
@@ -159,7 +159,7 @@
 		if (!(over & SNAME_FIELD) && packet->sname[0]) num_options++;
 	}
 
-	envp = xcalloc(sizeof(char *), num_options + 5);
+	envp = xzalloc(sizeof(char *) * (num_options + 5));
 	j = 0;
 	asprintf(&envp[j++], "interface=%s", client_config.interface);
 	asprintf(&envp[j++], "%s=%s", "PATH",




More information about the busybox-cvs mailing list