diff options
author | landley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-08-03 20:07:35 +0000 |
---|---|---|
committer | landley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-08-03 20:07:35 +0000 |
commit | e5765408936171c2e0c37c4eaca8e1a187ef4235 (patch) | |
tree | 2d31e921a759c769f339055c9946205fabef5cbf | |
parent | 2265911dfe0141d98022f3054f4af2c7976e0921 (diff) | |
download | busybox-w32-e5765408936171c2e0c37c4eaca8e1a187ef4235.tar.gz busybox-w32-e5765408936171c2e0c37c4eaca8e1a187ef4235.tar.bz2 busybox-w32-e5765408936171c2e0c37c4eaca8e1a187ef4235.zip |
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.
git-svn-id: svn://busybox.net/trunk/busybox@15771 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r-- | coreutils/cut.c | 4 | ||||
-rw-r--r-- | coreutils/ls.c | 2 | ||||
-rw-r--r-- | coreutils/sort.c | 2 | ||||
-rw-r--r-- | e2fsprogs/fsck.c | 4 | ||||
-rw-r--r-- | e2fsprogs/mke2fs.c | 2 | ||||
-rw-r--r-- | findutils/grep.c | 2 | ||||
-rw-r--r-- | findutils/xargs.c | 2 | ||||
-rw-r--r-- | include/libbb.h | 1 | ||||
-rw-r--r-- | libbb/xfuncs.c | 9 | ||||
-rw-r--r-- | modutils/insmod.c | 2 | ||||
-rw-r--r-- | modutils/modprobe.c | 4 | ||||
-rw-r--r-- | networking/httpd.c | 2 | ||||
-rw-r--r-- | networking/traceroute.c | 10 | ||||
-rw-r--r-- | shell/cmdedit.c | 4 | ||||
-rw-r--r-- | util-linux/fdisk.c | 4 |
15 files changed, 22 insertions, 32 deletions
diff --git a/coreutils/cut.c b/coreutils/cut.c index 98fdb5356..1b80e7e73 100644 --- a/coreutils/cut.c +++ b/coreutils/cut.c | |||
@@ -135,7 +135,7 @@ static void cut_line_by_chars(const char *line) | |||
135 | { | 135 | { |
136 | int c, l; | 136 | int c, l; |
137 | /* set up a list so we can keep track of what's been printed */ | 137 | /* set up a list so we can keep track of what's been printed */ |
138 | char *printed = xcalloc(strlen(line), sizeof(char)); | 138 | char *printed = xzalloc(strlen(line)); |
139 | 139 | ||
140 | /* print the chars specified in each cut list */ | 140 | /* print the chars specified in each cut list */ |
141 | for (c = 0; c < nlists; c++) { | 141 | for (c = 0; c < nlists; c++) { |
@@ -172,7 +172,7 @@ static void cut_line_by_fields(char *line) | |||
172 | } | 172 | } |
173 | 173 | ||
174 | /* set up a list so we can keep track of what's been printed */ | 174 | /* set up a list so we can keep track of what's been printed */ |
175 | printed = xcalloc(strlen(line), sizeof(char)); | 175 | printed = xzalloc(strlen(line)); |
176 | 176 | ||
177 | /* process each list on this line, for as long as we've got a line to process */ | 177 | /* process each list on this line, for as long as we've got a line to process */ |
178 | for (c = 0; c < nlists && line; c++) { | 178 | for (c = 0; c < nlists && line; c++) { |
diff --git a/coreutils/ls.c b/coreutils/ls.c index 6b9fbbfc9..828127a4a 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c | |||
@@ -300,7 +300,7 @@ static struct dnode **dnalloc(int num) | |||
300 | if (num < 1) | 300 | if (num < 1) |
301 | return (NULL); | 301 | return (NULL); |
302 | 302 | ||
303 | p = (struct dnode **) xcalloc((size_t) num, (size_t) (sizeof(struct dnode *))); | 303 | p = (struct dnode **) xzalloc(num * sizeof(struct dnode *)); |
304 | return (p); | 304 | return (p); |
305 | } | 305 | } |
306 | 306 | ||
diff --git a/coreutils/sort.c b/coreutils/sort.c index 195e13d13..ea7752d2a 100644 --- a/coreutils/sort.c +++ b/coreutils/sort.c | |||
@@ -120,7 +120,7 @@ static struct sort_key *add_key(void) | |||
120 | { | 120 | { |
121 | struct sort_key **pkey=&key_list; | 121 | struct sort_key **pkey=&key_list; |
122 | while(*pkey) pkey=&((*pkey)->next_key); | 122 | while(*pkey) pkey=&((*pkey)->next_key); |
123 | return *pkey=xcalloc(1,sizeof(struct sort_key)); | 123 | return *pkey = xzalloc(sizeof(struct sort_key)); |
124 | } | 124 | } |
125 | 125 | ||
126 | #define GET_LINE(fp) (global_flags&FLAG_z) ? bb_get_chunk_from_file(fp,NULL) \ | 126 | #define GET_LINE(fp) (global_flags&FLAG_z) ? bb_get_chunk_from_file(fp,NULL) \ |
diff --git a/e2fsprogs/fsck.c b/e2fsprogs/fsck.c index afb6f0c7d..99ffed1c5 100644 --- a/e2fsprogs/fsck.c +++ b/e2fsprogs/fsck.c | |||
@@ -877,8 +877,8 @@ static void compile_fs_type(char *fs_type, struct fs_type_compile *cmp) | |||
877 | } | 877 | } |
878 | } | 878 | } |
879 | 879 | ||
880 | cmp->list = xcalloc(num, sizeof(char *)); | 880 | cmp->list = xzalloc(num * sizeof(char *)); |
881 | cmp->type = xcalloc(num, sizeof(int)); | 881 | cmp->type = xzalloc(num * sizeof(int)); |
882 | cmp->negate = 0; | 882 | cmp->negate = 0; |
883 | 883 | ||
884 | if (!fs_type) | 884 | if (!fs_type) |
diff --git a/e2fsprogs/mke2fs.c b/e2fsprogs/mke2fs.c index ea6afb92c..687f18567 100644 --- a/e2fsprogs/mke2fs.c +++ b/e2fsprogs/mke2fs.c | |||
@@ -401,7 +401,7 @@ static errcode_t zero_blocks(ext2_filsys fs, blk_t blk, int num, | |||
401 | } | 401 | } |
402 | /* Allocate the zeroizing buffer if necessary */ | 402 | /* Allocate the zeroizing buffer if necessary */ |
403 | if (!buf) { | 403 | if (!buf) { |
404 | buf = xcalloc(fs->blocksize, STRIDE_LENGTH); | 404 | buf = xzalloc(fs->blocksize * STRIDE_LENGTH); |
405 | } | 405 | } |
406 | /* OK, do the write loop */ | 406 | /* OK, do the write loop */ |
407 | next_update = 0; | 407 | next_update = 0; |
diff --git a/findutils/grep.c b/findutils/grep.c index b53bf490a..c2c4e7095 100644 --- a/findutils/grep.c +++ b/findutils/grep.c | |||
@@ -321,7 +321,7 @@ int grep_main(int argc, char **argv) | |||
321 | lines_before = 0; | 321 | lines_before = 0; |
322 | lines_after = 0; | 322 | lines_after = 0; |
323 | } else if(lines_before > 0) | 323 | } else if(lines_before > 0) |
324 | before_buf = (char **)xcalloc(lines_before, sizeof(char *)); | 324 | before_buf = (char **)xzalloc(lines_before * sizeof(char *)); |
325 | } | 325 | } |
326 | #else | 326 | #else |
327 | /* with auto sanity checks */ | 327 | /* with auto sanity checks */ |
diff --git a/findutils/xargs.c b/findutils/xargs.c index e46708303..d067a3f48 100644 --- a/findutils/xargs.c +++ b/findutils/xargs.c | |||
@@ -503,7 +503,7 @@ int xargs_main(int argc, char **argv) | |||
503 | 503 | ||
504 | /* allocating pointers for execvp: | 504 | /* allocating pointers for execvp: |
505 | a*arg, n*arg from stdin, NULL */ | 505 | a*arg, n*arg from stdin, NULL */ |
506 | args = xcalloc(n + a + 1, sizeof(char *)); | 506 | args = xzalloc((n + a + 1) * sizeof(char *)); |
507 | 507 | ||
508 | /* Store the command to be executed | 508 | /* Store the command to be executed |
509 | (taken from the command line) */ | 509 | (taken from the command line) */ |
diff --git a/include/libbb.h b/include/libbb.h index 5b2977fce..745f8372b 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -230,7 +230,6 @@ void run_applet_by_name(const char *name, int argc, char **argv); | |||
230 | extern void *xmalloc(size_t size); | 230 | extern void *xmalloc(size_t size); |
231 | extern void *xrealloc(void *old, size_t size); | 231 | extern void *xrealloc(void *old, size_t size); |
232 | extern void *xzalloc(size_t size); | 232 | extern void *xzalloc(size_t size); |
233 | extern void *xcalloc(size_t nmemb, size_t size); | ||
234 | 233 | ||
235 | extern char *xstrdup (const char *s); | 234 | extern char *xstrdup (const char *s); |
236 | extern char *xstrndup (const char *s, int n); | 235 | extern char *xstrndup (const char *s, int n); |
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index 699d09c67..31f0febca 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c | |||
@@ -41,15 +41,6 @@ void *xzalloc(size_t size) | |||
41 | } | 41 | } |
42 | #endif | 42 | #endif |
43 | 43 | ||
44 | #ifdef L_xcalloc | ||
45 | void *xcalloc(size_t nmemb, size_t size) | ||
46 | { | ||
47 | void *ptr = calloc(nmemb, size); | ||
48 | if (ptr == NULL && nmemb != 0 && size != 0) | ||
49 | bb_error_msg_and_die(bb_msg_memory_exhausted); | ||
50 | return ptr; | ||
51 | } | ||
52 | #endif | ||
53 | #endif /* DMALLOC */ | 44 | #endif /* DMALLOC */ |
54 | 45 | ||
55 | #ifdef L_xstrdup | 46 | #ifdef L_xstrdup |
diff --git a/modutils/insmod.c b/modutils/insmod.c index be41e4449..614eb2f6b 100644 --- a/modutils/insmod.c +++ b/modutils/insmod.c | |||
@@ -3490,7 +3490,7 @@ static struct obj_file *obj_load(FILE * fp, int loadprogbits) | |||
3490 | 3490 | ||
3491 | /* Allocate space for a table of local symbols. */ | 3491 | /* Allocate space for a table of local symbols. */ |
3492 | j = f->local_symtab_size = sec->header.sh_info; | 3492 | j = f->local_symtab_size = sec->header.sh_info; |
3493 | f->local_symtab = xcalloc(j, sizeof(struct obj_symbol *)); | 3493 | f->local_symtab = xzalloc(j * sizeof(struct obj_symbol *)); |
3494 | 3494 | ||
3495 | /* Insert all symbols into the hash table. */ | 3495 | /* Insert all symbols into the hash table. */ |
3496 | for (j = 1, ++sym; j < nsym; ++j, ++sym) { | 3496 | for (j = 1, ++sym; j < nsym; ++j, ++sym) { |
diff --git a/modutils/modprobe.c b/modutils/modprobe.c index 5a94c7c92..efb119e3e 100644 --- a/modutils/modprobe.c +++ b/modutils/modprobe.c | |||
@@ -294,10 +294,10 @@ static void include_conf ( struct dep_t **first, struct dep_t **current, char *b | |||
294 | if ( parse_tag_value ( buffer + 6, &alias, &mod )) { | 294 | if ( parse_tag_value ( buffer + 6, &alias, &mod )) { |
295 | /* handle alias as a module dependent on the aliased module */ | 295 | /* handle alias as a module dependent on the aliased module */ |
296 | if ( !*current ) { | 296 | if ( !*current ) { |
297 | (*first) = (*current) = (struct dep_t *) xcalloc ( 1, sizeof ( struct dep_t )); | 297 | (*first) = (*current) = (struct dep_t *) xzalloc (sizeof ( struct dep_t )); |
298 | } | 298 | } |
299 | else { | 299 | else { |
300 | (*current)-> m_next = (struct dep_t *) xcalloc ( 1, sizeof ( struct dep_t )); | 300 | (*current)-> m_next = (struct dep_t *) xzalloc (sizeof ( struct dep_t )); |
301 | (*current) = (*current)-> m_next; | 301 | (*current) = (*current)-> m_next; |
302 | } | 302 | } |
303 | (*current)-> m_name = xstrdup ( alias ); | 303 | (*current)-> m_name = xstrdup ( alias ); |
diff --git a/networking/httpd.c b/networking/httpd.c index 4e0ab92d5..8852cbb62 100644 --- a/networking/httpd.c +++ b/networking/httpd.c | |||
@@ -1929,7 +1929,7 @@ int httpd_main(int argc, char *argv[]) | |||
1929 | 1929 | ||
1930 | USE_FEATURE_HTTPD_AUTH_MD5(const char *pass;) | 1930 | USE_FEATURE_HTTPD_AUTH_MD5(const char *pass;) |
1931 | 1931 | ||
1932 | config = xcalloc(1, sizeof(*config)); | 1932 | config = xzalloc(sizeof(*config)); |
1933 | #ifdef CONFIG_FEATURE_HTTPD_BASIC_AUTH | 1933 | #ifdef CONFIG_FEATURE_HTTPD_BASIC_AUTH |
1934 | config->realm = "Web Server Authentication"; | 1934 | config->realm = "Web Server Authentication"; |
1935 | #endif | 1935 | #endif |
diff --git a/networking/traceroute.c b/networking/traceroute.c index 446490303..9c1d6346e 100644 --- a/networking/traceroute.c +++ b/networking/traceroute.c | |||
@@ -375,7 +375,7 @@ ifaddrlist(struct IFADDRLIST **ipaddrp) | |||
375 | ifend = (struct ifreq *)((char *)ibuf + ifc.ifc_len); | 375 | ifend = (struct ifreq *)((char *)ibuf + ifc.ifc_len); |
376 | 376 | ||
377 | nipaddr = 1 + (ifc.ifc_len / sizeof(struct ifreq)); | 377 | nipaddr = 1 + (ifc.ifc_len / sizeof(struct ifreq)); |
378 | st_ifaddrlist = xcalloc(nipaddr, sizeof(struct IFADDRLIST)); | 378 | st_ifaddrlist = xzalloc(nipaddr * sizeof(struct IFADDRLIST)); |
379 | al = st_ifaddrlist; | 379 | al = st_ifaddrlist; |
380 | nipaddr = 0; | 380 | nipaddr = 0; |
381 | 381 | ||
@@ -872,12 +872,12 @@ gethostinfo(const char *host) | |||
872 | char **p; | 872 | char **p; |
873 | u_int32_t addr, *ap; | 873 | u_int32_t addr, *ap; |
874 | 874 | ||
875 | hi = xcalloc(1, sizeof(*hi)); | 875 | hi = xzalloc(sizeof(*hi)); |
876 | addr = inet_addr(host); | 876 | addr = inet_addr(host); |
877 | if ((int32_t)addr != -1) { | 877 | if ((int32_t)addr != -1) { |
878 | hi->name = xstrdup(host); | 878 | hi->name = xstrdup(host); |
879 | hi->n = 1; | 879 | hi->n = 1; |
880 | hi->addrs = xcalloc(1, sizeof(hi->addrs[0])); | 880 | hi->addrs = xzalloc(sizeof(hi->addrs[0])); |
881 | hi->addrs[0] = addr; | 881 | hi->addrs[0] = addr; |
882 | return hi; | 882 | return hi; |
883 | } | 883 | } |
@@ -889,7 +889,7 @@ gethostinfo(const char *host) | |||
889 | for (n = 0, p = hp->h_addr_list; *p != NULL; ++n, ++p) | 889 | for (n = 0, p = hp->h_addr_list; *p != NULL; ++n, ++p) |
890 | continue; | 890 | continue; |
891 | hi->n = n; | 891 | hi->n = n; |
892 | hi->addrs = xcalloc(n, sizeof(hi->addrs[0])); | 892 | hi->addrs = xzalloc(n * sizeof(hi->addrs[0])); |
893 | for (ap = hi->addrs, p = hp->h_addr_list; *p != NULL; ++ap, ++p) | 893 | for (ap = hi->addrs, p = hp->h_addr_list; *p != NULL; ++ap, ++p) |
894 | memcpy(ap, *p, sizeof(*ap)); | 894 | memcpy(ap, *p, sizeof(*ap)); |
895 | return hi; | 895 | return hi; |
@@ -1161,7 +1161,7 @@ traceroute_main(int argc, char *argv[]) | |||
1161 | xsetgid(getgid()); | 1161 | xsetgid(getgid()); |
1162 | xsetuid(getuid()); | 1162 | xsetuid(getuid()); |
1163 | 1163 | ||
1164 | outip = (struct ip *)xcalloc(1, (unsigned)packlen); | 1164 | outip = (struct ip *)xzalloc(packlen); |
1165 | 1165 | ||
1166 | outip->ip_v = IPVERSION; | 1166 | outip->ip_v = IPVERSION; |
1167 | if (tos_str) | 1167 | if (tos_str) |
diff --git a/shell/cmdedit.c b/shell/cmdedit.c index 0af1a2ad0..03aaa3b2e 100644 --- a/shell/cmdedit.c +++ b/shell/cmdedit.c | |||
@@ -311,7 +311,7 @@ static void parse_prompt(const char *prmt_ptr) | |||
311 | int prmt_len = 0; | 311 | int prmt_len = 0; |
312 | size_t cur_prmt_len = 0; | 312 | size_t cur_prmt_len = 0; |
313 | char flg_not_length = '['; | 313 | char flg_not_length = '['; |
314 | char *prmt_mem_ptr = xcalloc(1, 1); | 314 | char *prmt_mem_ptr = xzalloc(1); |
315 | char *pwd_buf = xgetcwd(0); | 315 | char *pwd_buf = xgetcwd(0); |
316 | char buf2[PATH_MAX + 1]; | 316 | char buf2[PATH_MAX + 1]; |
317 | char buf[2]; | 317 | char buf[2]; |
@@ -344,7 +344,7 @@ static void parse_prompt(const char *prmt_ptr) | |||
344 | case 'h': | 344 | case 'h': |
345 | pbuf = hostname_buf; | 345 | pbuf = hostname_buf; |
346 | if (pbuf == 0) { | 346 | if (pbuf == 0) { |
347 | pbuf = xcalloc(256, 1); | 347 | pbuf = xzalloc(256); |
348 | if (gethostname(pbuf, 255) < 0) { | 348 | if (gethostname(pbuf, 255) < 0) { |
349 | strcpy(pbuf, "?"); | 349 | strcpy(pbuf, "?"); |
350 | } else { | 350 | } else { |
diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c index 1c935463e..310bd555e 100644 --- a/util-linux/fdisk.c +++ b/util-linux/fdisk.c | |||
@@ -5162,7 +5162,7 @@ add_partition(int n, int sys) | |||
5162 | ext_index = n; | 5162 | ext_index = n; |
5163 | pen->ext_pointer = p; | 5163 | pen->ext_pointer = p; |
5164 | pe4->offset = extended_offset = start; | 5164 | pe4->offset = extended_offset = start; |
5165 | pe4->sectorbuffer = xcalloc(1, sector_size); | 5165 | pe4->sectorbuffer = xzalloc(sector_size); |
5166 | pe4->part_table = pt_offset(pe4->sectorbuffer, 0); | 5166 | pe4->part_table = pt_offset(pe4->sectorbuffer, 0); |
5167 | pe4->ext_pointer = pe4->part_table + 1; | 5167 | pe4->ext_pointer = pe4->part_table + 1; |
5168 | pe4->changed = 1; | 5168 | pe4->changed = 1; |
@@ -5176,7 +5176,7 @@ add_logical(void) | |||
5176 | if (partitions > 5 || ptes[4].part_table->sys_ind) { | 5176 | if (partitions > 5 || ptes[4].part_table->sys_ind) { |
5177 | struct pte *pe = &ptes[partitions]; | 5177 | struct pte *pe = &ptes[partitions]; |
5178 | 5178 | ||
5179 | pe->sectorbuffer = xcalloc(1, sector_size); | 5179 | pe->sectorbuffer = xzalloc(sector_size); |
5180 | pe->part_table = pt_offset(pe->sectorbuffer, 0); | 5180 | pe->part_table = pt_offset(pe->sectorbuffer, 0); |
5181 | pe->ext_pointer = pe->part_table + 1; | 5181 | pe->ext_pointer = pe->part_table + 1; |
5182 | pe->offset = 0; | 5182 | pe->offset = 0; |