svn commit: trunk/busybox: modutils networking/udhcp

vda at busybox.net vda at busybox.net
Wed Aug 27 22:29:43 UTC 2008


Author: vda
Date: 2008-08-27 15:29:43 -0700 (Wed, 27 Aug 2008)
New Revision: 23271

Log:
insmod: shrink

function                                             old     new   delta
obj_allocate_commons                                 488     462     -26
insmod_main                                         3830    3714    -116



Modified:
   trunk/busybox/modutils/insmod.c
   trunk/busybox/networking/udhcp/dhcpc.c


Changeset:
Modified: trunk/busybox/modutils/insmod.c
===================================================================
--- trunk/busybox/modutils/insmod.c	2008-08-27 21:31:23 UTC (rev 23270)
+++ trunk/busybox/modutils/insmod.c	2008-08-27 22:29:43 UTC (rev 23271)
@@ -2212,7 +2212,7 @@
 	sec->name = name;
 	sec->idx = newidx;
 	if (size)
-		sec->contents = xmalloc(size);
+		sec->contents = xzalloc(size);
 
 	obj_insert_section_load_order(f, sec);
 
@@ -2227,7 +2227,7 @@
 	int newidx = f->header.e_shnum++;
 	struct obj_section *sec;
 
-	f->sections = xrealloc(f->sections, (newidx + 1) * sizeof(sec));
+	f->sections = xrealloc_vector(f->sections, 2, newidx);
 	f->sections[newidx] = sec = arch_new_section();
 
 	sec->header.sh_type = SHT_PROGBITS;
@@ -2237,7 +2237,7 @@
 	sec->name = name;
 	sec->idx = newidx;
 	if (size)
-		sec->contents = xmalloc(size);
+		sec->contents = xzalloc(size);
 
 	sec->load_next = f->load_order;
 	f->load_order = sec;
@@ -2689,8 +2689,7 @@
 	/* Collect the modules' symbols.  */
 
 	if (nmod) {
-		ext_modules = modules = xmalloc(nmod * sizeof(*modules));
-		memset(modules, 0, nmod * sizeof(*modules));
+		ext_modules = modules = xzalloc(nmod * sizeof(*modules));
 		for (i = 0, mn = module_names, m = modules;
 				i < nmod; ++i, ++m, mn += strlen(mn) + 1) {
 			struct new_module_info info;
@@ -2770,13 +2769,14 @@
 }
 
 
-static void  new_create_this_module(struct obj_file *f, const char *m_name)
+static void new_create_this_module(struct obj_file *f, const char *m_name)
 {
 	struct obj_section *sec;
 
 	sec = obj_create_alloced_section_first(f, ".this", tgt_sizeof_long,
 			sizeof(struct new_module));
-	memset(sec->contents, 0, sizeof(struct new_module));
+	/* done by obj_create_alloced_section_first: */
+	/*memset(sec->contents, 0, sizeof(struct new_module));*/
 
 	obj_add_symbol(f, SPFX "__this_module", -1,
 			ELF_ST_INFO(STB_LOCAL, STT_OBJECT), sec->idx, 0,
@@ -3083,9 +3083,9 @@
 		if (i == f->header.e_shnum) {
 			struct obj_section *sec;
 
+			f->header.e_shnum++;
 			f->sections = xrealloc_vector(f->sections, 2, i);
 			f->sections[i] = sec = arch_new_section();
-			f->header.e_shnum = i + 1;
 
 			sec->header.sh_type = SHT_PROGBITS;
 			sec->header.sh_flags = SHF_WRITE | SHF_ALLOC;
@@ -3124,12 +3124,9 @@
 	for (i = 0; i < f->header.e_shnum; ++i) {
 		struct obj_section *s = f->sections[i];
 		if (s->header.sh_type == SHT_NOBITS) {
+			s->contents = NULL;
 			if (s->header.sh_size != 0)
-				s->contents = memset(xmalloc(s->header.sh_size),
-						0, s->header.sh_size);
-			else
-				s->contents = NULL;
-
+				s->contents = xzalloc(s->header.sh_size),
 			s->header.sh_type = SHT_PROGBITS;
 		}
 	}
@@ -3354,8 +3351,7 @@
 	}
 
 	shnum = f->header.e_shnum;
-	f->sections = xmalloc(sizeof(struct obj_section *) * shnum);
-	memset(f->sections, 0, sizeof(struct obj_section *) * shnum);
+	f->sections = xzalloc(sizeof(struct obj_section *) * shnum);
 
 	section_headers = alloca(sizeof(ElfW(Shdr)) * shnum);
 	fseek(fp, f->header.e_shoff, SEEK_SET);
@@ -3391,14 +3387,13 @@
 			case SHT_SYMTAB:
 			case SHT_STRTAB:
 			case SHT_RELM:
+				sec->contents = NULL;
 				if (sec->header.sh_size > 0) {
-					sec->contents = xmalloc(sec->header.sh_size);
+					sec->contents = xzalloc(sec->header.sh_size);
 					fseek(fp, sec->header.sh_offset, SEEK_SET);
 					if (fread(sec->contents, sec->header.sh_size, 1, fp) != 1) {
 						bb_perror_msg_and_die("error reading ELF section data");
 					}
-				} else {
-					sec->contents = NULL;
 				}
 				break;
 

Modified: trunk/busybox/networking/udhcp/dhcpc.c
===================================================================
--- trunk/busybox/networking/udhcp/dhcpc.c	2008-08-27 21:31:23 UTC (rev 23270)
+++ trunk/busybox/networking/udhcp/dhcpc.c	2008-08-27 22:29:43 UTC (rev 23271)
@@ -259,9 +259,10 @@
 	if (opt & OPT_o)
 		client_config.no_default_options = 1;
 	while (list_O) {
-		int n = index_in_strings(dhcp_option_strings, llist_pop(&list_O));
+		char *optstr = llist_pop(&list_O);
+		int n = index_in_strings(dhcp_option_strings, optstr);
 		if (n < 0)
-			bb_error_msg_and_die("unknown option '%s'", list_O->data);
+			bb_error_msg_and_die("unknown option '%s'", optstr);
 		n = dhcp_options[n].code;
 		client_config.opt_mask[n >> 3] |= 1 << (n & 7);
 	}




More information about the busybox-cvs mailing list