diff options
author | landley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-05-21 18:30:35 +0000 |
---|---|---|
committer | landley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-05-21 18:30:35 +0000 |
commit | 8f30399d9a813414e47d89bed9efbc9e84ae697d (patch) | |
tree | b126ca6ff7d2db91fa3525c6e5d3978932137fa3 | |
parent | 2cf3fce2b8fbc52ee550cebf6363a737950703a0 (diff) | |
download | busybox-w32-8f30399d9a813414e47d89bed9efbc9e84ae697d.tar.gz busybox-w32-8f30399d9a813414e47d89bed9efbc9e84ae697d.tar.bz2 busybox-w32-8f30399d9a813414e47d89bed9efbc9e84ae697d.zip |
Minor cleanups: Convert a few calloc() calls to xzalloc, remove unnecessary
memset, collate variable declarations...
git-svn-id: svn://busybox.net/trunk/busybox@15156 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r-- | editors/awk.c | 16 | ||||
-rw-r--r-- | editors/sed.c | 4 | ||||
-rw-r--r-- | networking/udhcp/dhcpd.c | 24 | ||||
-rw-r--r-- | networking/udhcp/script.c | 2 |
4 files changed, 17 insertions, 29 deletions
diff --git a/editors/awk.c b/editors/awk.c index f4eb1ab90..74f9d8e54 100644 --- a/editors/awk.c +++ b/editors/awk.c | |||
@@ -474,9 +474,9 @@ static xhash *hash_init(void) | |||
474 | { | 474 | { |
475 | xhash *newhash; | 475 | xhash *newhash; |
476 | 476 | ||
477 | newhash = (xhash *)xcalloc(1, sizeof(xhash)); | 477 | newhash = (xhash *)xzalloc(sizeof(xhash)); |
478 | newhash->csize = FIRST_PRIME; | 478 | newhash->csize = FIRST_PRIME; |
479 | newhash->items = (hash_item **)xcalloc(newhash->csize, sizeof(hash_item *)); | 479 | newhash->items = (hash_item **)xzalloc(newhash->csize * sizeof(hash_item *)); |
480 | 480 | ||
481 | return newhash; | 481 | return newhash; |
482 | } | 482 | } |
@@ -505,7 +505,7 @@ static void hash_rebuild(xhash *hash) | |||
505 | return; | 505 | return; |
506 | 506 | ||
507 | newsize = PRIMES[hash->nprime++]; | 507 | newsize = PRIMES[hash->nprime++]; |
508 | newitems = (hash_item **)xcalloc(newsize, sizeof(hash_item *)); | 508 | newitems = (hash_item **)xzalloc(newsize * sizeof(hash_item *)); |
509 | 509 | ||
510 | for (i=0; i<hash->csize; i++) { | 510 | for (i=0; i<hash->csize; i++) { |
511 | hi = hash->items[i]; | 511 | hi = hash->items[i]; |
@@ -536,7 +536,7 @@ static void *hash_find(xhash *hash, const char *name) | |||
536 | hash_rebuild(hash); | 536 | hash_rebuild(hash); |
537 | 537 | ||
538 | l = strlen(name) + 1; | 538 | l = strlen(name) + 1; |
539 | hi = xcalloc(sizeof(hash_item) + l, 1); | 539 | hi = xzalloc(sizeof(hash_item) + l); |
540 | memcpy(hi->name, name, l); | 540 | memcpy(hi->name, name, l); |
541 | 541 | ||
542 | idx = hashidx(name) % hash->csize; | 542 | idx = hashidx(name) % hash->csize; |
@@ -993,7 +993,7 @@ static node *new_node(uint32_t info) | |||
993 | { | 993 | { |
994 | register node *n; | 994 | register node *n; |
995 | 995 | ||
996 | n = (node *)xcalloc(sizeof(node), 1); | 996 | n = (node *)xzalloc(sizeof(node)); |
997 | n->info = info; | 997 | n->info = info; |
998 | n->lineno = lineno; | 998 | n->lineno = lineno; |
999 | return n; | 999 | return n; |
@@ -1095,7 +1095,7 @@ static node *parse_expr(uint32_t iexp) | |||
1095 | case TC_NUMBER: | 1095 | case TC_NUMBER: |
1096 | case TC_STRING: | 1096 | case TC_STRING: |
1097 | cn->info = OC_VAR; | 1097 | cn->info = OC_VAR; |
1098 | v = cn->l.v = xcalloc(sizeof(var), 1); | 1098 | v = cn->l.v = xzalloc(sizeof(var)); |
1099 | if (tc & TC_NUMBER) | 1099 | if (tc & TC_NUMBER) |
1100 | setvar_i(v, t.number); | 1100 | setvar_i(v, t.number); |
1101 | else | 1101 | else |
@@ -1104,7 +1104,7 @@ static node *parse_expr(uint32_t iexp) | |||
1104 | 1104 | ||
1105 | case TC_REGEXP: | 1105 | case TC_REGEXP: |
1106 | mk_re_node(t.string, cn, | 1106 | mk_re_node(t.string, cn, |
1107 | (regex_t *)xcalloc(sizeof(regex_t),2)); | 1107 | (regex_t *)xzalloc(sizeof(regex_t)*2)); |
1108 | break; | 1108 | break; |
1109 | 1109 | ||
1110 | case TC_FUNCTION: | 1110 | case TC_FUNCTION: |
@@ -1590,7 +1590,7 @@ static void hashwalk_init(var *v, xhash *array) | |||
1590 | free(v->x.walker); | 1590 | free(v->x.walker); |
1591 | 1591 | ||
1592 | v->type |= VF_WALK; | 1592 | v->type |= VF_WALK; |
1593 | w = v->x.walker = (char **)xcalloc(2 + 2*sizeof(char *) + array->glen, 1); | 1593 | w = v->x.walker = (char **)xzalloc(2 + 2*sizeof(char *) + array->glen); |
1594 | *w = *(w+1) = (char *)(w + 2); | 1594 | *w = *(w+1) = (char *)(w + 2); |
1595 | for (i=0; i<array->csize; i++) { | 1595 | for (i=0; i<array->csize; i++) { |
1596 | hi = array->items[i]; | 1596 | hi = array->items[i]; |
diff --git a/editors/sed.c b/editors/sed.c index 893931153..39b28d006 100644 --- a/editors/sed.c +++ b/editors/sed.c | |||
@@ -449,7 +449,7 @@ static char *parse_cmd_args(sed_cmd_t *sed_cmd, char *cmdstr) | |||
449 | parse_escapes(match,match,strlen(match),i,i); | 449 | parse_escapes(match,match,strlen(match),i,i); |
450 | parse_escapes(replace,replace,strlen(replace),i,i); | 450 | parse_escapes(replace,replace,strlen(replace),i,i); |
451 | 451 | ||
452 | sed_cmd->string = xcalloc(1, (strlen(match) + 1) * 2); | 452 | sed_cmd->string = xzalloc((strlen(match) + 1) * 2); |
453 | for (i = 0; match[i] && replace[i]; i++) { | 453 | for (i = 0; match[i] && replace[i]; i++) { |
454 | sed_cmd->string[i * 2] = match[i]; | 454 | sed_cmd->string[i * 2] = match[i]; |
455 | sed_cmd->string[(i * 2) + 1] = replace[i]; | 455 | sed_cmd->string[(i * 2) + 1] = replace[i]; |
@@ -513,7 +513,7 @@ static void add_cmd(char *cmdstr) | |||
513 | * part1 part2 part3 | 513 | * part1 part2 part3 |
514 | */ | 514 | */ |
515 | 515 | ||
516 | sed_cmd = xcalloc(1, sizeof(sed_cmd_t)); | 516 | sed_cmd = xzalloc(sizeof(sed_cmd_t)); |
517 | 517 | ||
518 | /* first part (if present) is an address: either a '$', a number or a /regex/ */ | 518 | /* first part (if present) is an address: either a '$', a number or a /regex/ */ |
519 | cmdstr += get_address(cmdstr, &sed_cmd->beg_line, &sed_cmd->beg_match); | 519 | cmdstr += get_address(cmdstr, &sed_cmd->beg_line, &sed_cmd->beg_match); |
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c index 0dfc0b559..28acb6bcc 100644 --- a/networking/udhcp/dhcpd.c +++ b/networking/udhcp/dhcpd.c | |||
@@ -52,30 +52,18 @@ struct dhcpOfferedAddr *leases; | |||
52 | struct server_config_t server_config; | 52 | struct server_config_t server_config; |
53 | 53 | ||
54 | 54 | ||
55 | #ifdef COMBINED_BINARY | ||
56 | int udhcpd_main(int argc, char *argv[]) | 55 | int udhcpd_main(int argc, char *argv[]) |
57 | #else | ||
58 | int main(int argc, char *argv[]) | ||
59 | #endif | ||
60 | { | 56 | { |
61 | fd_set rfds; | 57 | fd_set rfds; |
62 | struct timeval tv; | 58 | struct timeval tv; |
63 | int server_socket = -1; | 59 | int server_socket = -1, bytes, retval, max_sock; |
64 | int bytes, retval; | ||
65 | struct dhcpMessage packet; | 60 | struct dhcpMessage packet; |
66 | uint8_t *state; | 61 | uint8_t *state, *server_id, *requested; |
67 | uint8_t *server_id, *requested; | 62 | uint32_t server_id_align, requested_align, static_lease_ip; |
68 | uint32_t server_id_align, requested_align; | 63 | unsigned long timeout_end, num_ips; |
69 | unsigned long timeout_end; | ||
70 | struct option_set *option; | 64 | struct option_set *option; |
71 | struct dhcpOfferedAddr *lease; | 65 | struct dhcpOfferedAddr *lease, static_lease; |
72 | struct dhcpOfferedAddr static_lease; | ||
73 | int max_sock; | ||
74 | unsigned long num_ips; | ||
75 | |||
76 | uint32_t static_lease_ip; | ||
77 | 66 | ||
78 | memset(&server_config, 0, sizeof(struct server_config_t)); | ||
79 | read_config(argc < 2 ? DHCPD_CONF_FILE : argv[1]); | 67 | read_config(argc < 2 ? DHCPD_CONF_FILE : argv[1]); |
80 | 68 | ||
81 | /* Start the log, sanitize fd's, and write a pid file */ | 69 | /* Start the log, sanitize fd's, and write a pid file */ |
@@ -96,7 +84,7 @@ int main(int argc, char *argv[]) | |||
96 | server_config.max_leases = num_ips; | 84 | server_config.max_leases = num_ips; |
97 | } | 85 | } |
98 | 86 | ||
99 | leases = xcalloc(server_config.max_leases, sizeof(struct dhcpOfferedAddr)); | 87 | leases = xzalloc(server_config.max_leases * sizeof(struct dhcpOfferedAddr)); |
100 | read_leases(server_config.lease_file); | 88 | read_leases(server_config.lease_file); |
101 | 89 | ||
102 | if (read_interface(server_config.interface, &server_config.ifindex, | 90 | if (read_interface(server_config.interface, &server_config.ifindex, |
diff --git a/networking/udhcp/script.c b/networking/udhcp/script.c index b6b0e0d59..2a4732104 100644 --- a/networking/udhcp/script.c +++ b/networking/udhcp/script.c | |||
@@ -159,7 +159,7 @@ static char **fill_envp(struct dhcpMessage *packet) | |||
159 | if (!(over & SNAME_FIELD) && packet->sname[0]) num_options++; | 159 | if (!(over & SNAME_FIELD) && packet->sname[0]) num_options++; |
160 | } | 160 | } |
161 | 161 | ||
162 | envp = xcalloc(sizeof(char *), num_options + 5); | 162 | envp = xzalloc(sizeof(char *) * (num_options + 5)); |
163 | j = 0; | 163 | j = 0; |
164 | asprintf(&envp[j++], "interface=%s", client_config.interface); | 164 | asprintf(&envp[j++], "interface=%s", client_config.interface); |
165 | asprintf(&envp[j++], "%s=%s", "PATH", | 165 | asprintf(&envp[j++], "%s=%s", "PATH", |