1
0
mirror of https://github.com/moparisthebest/wget synced 2024-07-03 16:38:41 -04:00

[svn] Use new macros xnew, xnew0, xnew_array, and xnew0_array in various places.

This commit is contained in:
hniksic 2003-10-31 06:55:50 -08:00
parent 370ff7a576
commit 5f0a2b3f08
17 changed files with 43 additions and 63 deletions

View File

@ -1,3 +1,8 @@
2003-10-31 Hrvoje Niksic <hniksic@xemacs.org>
* various: Use new macros xnew, xnew0, xnew_array, and xnew0_array
in various places.
2003-10-31 Hrvoje Niksic <hniksic@xemacs.org> 2003-10-31 Hrvoje Niksic <hniksic@xemacs.org>
* wget.h: Move declarations of malloc and logging code to * wget.h: Move declarations of malloc and logging code to

View File

@ -403,7 +403,7 @@ bindport (const ip_address *bind_address, int *port, int *local_sock)
int optval; int optval;
struct sockaddr_storage ss; struct sockaddr_storage ss;
struct sockaddr *sa = (struct sockaddr *)&ss; struct sockaddr *sa = (struct sockaddr *)&ss;
memset (&ss, 0, sizeof (ss)); xzero (ss);
#ifdef ENABLE_IPV6 #ifdef ENABLE_IPV6
if (bind_address->type == IPV6_ADDRESS) if (bind_address->type == IPV6_ADDRESS)

View File

@ -465,8 +465,8 @@ write_backup_file (const char *file, downloaded_file_t downloaded_file_return)
list. list.
-- Hrvoje Niksic <hniksic@xemacs.org> -- Hrvoje Niksic <hniksic@xemacs.org>
*/ */
converted_file_ptr = xmalloc(sizeof(*converted_file_ptr)); converted_file_ptr = xmalloc (sizeof (*converted_file_ptr));
converted_file_ptr->string = xstrdup(file); /* die on out-of-mem. */ converted_file_ptr->string = xstrdup (file);
converted_file_ptr->next = converted_files; converted_file_ptr->next = converted_files;
converted_files = converted_file_ptr; converted_files = converted_file_ptr;
} }

View File

@ -90,7 +90,7 @@ time_t cookies_now;
struct cookie_jar * struct cookie_jar *
cookie_jar_new (void) cookie_jar_new (void)
{ {
struct cookie_jar *jar = xmalloc (sizeof (struct cookie_jar)); struct cookie_jar *jar = xnew (struct cookie_jar);
jar->chains = make_nocase_string_hash_table (0); jar->chains = make_nocase_string_hash_table (0);
jar->cookie_count = 0; jar->cookie_count = 0;
return jar; return jar;
@ -130,8 +130,7 @@ struct cookie {
static struct cookie * static struct cookie *
cookie_new (void) cookie_new (void)
{ {
struct cookie *cookie = xmalloc (sizeof (struct cookie)); struct cookie *cookie = xnew0 (struct cookie);
memset (cookie, '\0', sizeof (struct cookie));
/* Both cookie->permanent and cookie->expiry_time are now 0. By /* Both cookie->permanent and cookie->expiry_time are now 0. By
default, we assume that the cookie is non-permanent and valid default, we assume that the cookie is non-permanent and valid

View File

@ -2124,7 +2124,7 @@ btoe (char *store, const char *c)
*store = '\0'; *store = '\0';
/* Workaround for extract() reads beyond end of data */ /* Workaround for extract() reads beyond end of data */
memset (cp, 0, sizeof(cp)); xzero (cp);
memcpy (cp, c, 8); memcpy (cp, c, 8);
/* Compute parity. */ /* Compute parity. */
for (p = 0, i = 0; i < 64; i += 2) for (p = 0, i = 0; i < 64; i += 2)

View File

@ -149,8 +149,8 @@ ssl_printerrors (void)
int ocerr = 0; int ocerr = 0;
unsigned long curerr = 0; unsigned long curerr = 0;
char errbuff[1024]; char errbuff[1024];
memset(errbuff, 0, sizeof(errbuff)); xzero (errbuff);
while ( 0 != (curerr = ERR_get_error ())) while ((curerr = ERR_get_error ()) != 0)
{ {
DEBUGP (("OpenSSL: %s\n", ERR_error_string (curerr, errbuff))); DEBUGP (("OpenSSL: %s\n", ERR_error_string (curerr, errbuff)));
++ocerr; ++ocerr;

View File

@ -263,8 +263,7 @@ hash_table_new (int items,
int (*test_function) (const void *, const void *)) int (*test_function) (const void *, const void *))
{ {
int size; int size;
struct hash_table *ht struct hash_table *ht = xnew (struct hash_table);
= (struct hash_table *)xmalloc (sizeof (struct hash_table));
ht->hash_function = hash_function ? hash_function : ptrhash; ht->hash_function = hash_function ? hash_function : ptrhash;
ht->test_function = test_function ? test_function : ptrcmp; ht->test_function = test_function ? test_function : ptrcmp;
@ -279,9 +278,7 @@ hash_table_new (int items,
ht->resize_threshold = size * HASH_FULLNESS_THRESHOLD; ht->resize_threshold = size * HASH_FULLNESS_THRESHOLD;
/*assert (ht->resize_threshold >= items);*/ /*assert (ht->resize_threshold >= items);*/
ht->mappings = xmalloc (ht->size * sizeof (struct mapping)); ht->mappings = xnew0_array (struct mapping, ht->size);
memset (ht->mappings, '\0', ht->size * sizeof (struct mapping));
ht->count = 0; ht->count = 0;
return ht; return ht;
@ -382,9 +379,7 @@ grow_hash_table (struct hash_table *ht)
ht->size = newsize; ht->size = newsize;
ht->resize_threshold = newsize * HASH_FULLNESS_THRESHOLD; ht->resize_threshold = newsize * HASH_FULLNESS_THRESHOLD;
mappings = xmalloc (ht->size * sizeof (struct mapping)); ht->mappings = mappings = xnew0_array (struct mapping, ht->size);
memset (mappings, '\0', ht->size * sizeof (struct mapping));
ht->mappings = mappings;
for (mp = old_mappings; mp < old_end; mp++) for (mp = old_mappings; mp < old_end; mp++)
if (NON_EMPTY (mp)) if (NON_EMPTY (mp))

View File

@ -236,11 +236,9 @@ address_list_from_addrinfo (const struct addrinfo *ai)
if (cnt == 0) if (cnt == 0)
return NULL; return NULL;
al = xmalloc (sizeof (struct address_list)); al = xnew0 (struct address_list);
al->addresses = xmalloc (cnt * sizeof (ip_address)); al->addresses = xnew_array (ip_address, cnt);
al->count = cnt; al->count = cnt;
al->faulty = 0;
al->from_cache = 0;
al->refcount = 1; al->refcount = 1;
ip = al->addresses; ip = al->addresses;
@ -275,17 +273,15 @@ static struct address_list *
address_list_from_ipv4_addresses (char **h_addr_list) address_list_from_ipv4_addresses (char **h_addr_list)
{ {
int count, i; int count, i;
struct address_list *al = xmalloc (sizeof (struct address_list)); struct address_list *al = xnew0 (struct address_list);
count = 0; count = 0;
while (h_addr_list[count]) while (h_addr_list[count])
++count; ++count;
assert (count > 0); assert (count > 0);
al->addresses = xnew_array (ip_address, count);
al->count = count; al->count = count;
al->faulty = 0;
al->addresses = xmalloc (count * sizeof (ip_address));
al->from_cache = 0;
al->refcount = 1; al->refcount = 1;
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
@ -496,7 +492,7 @@ lookup_host (const char *host, int flags)
flag. Without IPv6, we use inet_addr succeeds. */ flag. Without IPv6, we use inet_addr succeeds. */
#ifdef ENABLE_IPV6 #ifdef ENABLE_IPV6
memset (&hints, 0, sizeof (hints)); xzero (hints);
hints.ai_family = family; hints.ai_family = family;
hints.ai_socktype = SOCK_STREAM; hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_NUMERICHOST; hints.ai_flags = AI_NUMERICHOST;
@ -549,7 +545,7 @@ lookup_host (const char *host, int flags)
#ifdef ENABLE_IPV6 #ifdef ENABLE_IPV6
{ {
memset (&hints, 0, sizeof (hints)); xzero (hints);
hints.ai_family = family; hints.ai_family = family;
hints.ai_socktype = SOCK_STREAM; hints.ai_socktype = SOCK_STREAM;
if (flags & LH_PASSIVE) if (flags & LH_PASSIVE)

View File

@ -327,9 +327,7 @@ append_url (const char *link_uri,
DEBUGP (("appending \"%s\" to urlpos.\n", url->url)); DEBUGP (("appending \"%s\" to urlpos.\n", url->url));
newel = (struct urlpos *)xmalloc (sizeof (struct urlpos)); newel = xnew0 (struct urlpos);
memset (newel, 0, sizeof (*newel));
newel->next = NULL; newel->next = NULL;
newel->url = url; newel->url = url;
newel->pos = tag->attrs[attrind].value_raw_beginning - ctx->text; newel->pos = tag->attrs[attrind].value_raw_beginning - ctx->text;
@ -700,8 +698,7 @@ get_urls_file (const char *file)
} }
xfree (url_text); xfree (url_text);
entry = (struct urlpos *)xmalloc (sizeof (struct urlpos)); entry = xnew0 (struct urlpos);
memset (entry, 0, sizeof (*entry));
entry->next = NULL; entry->next = NULL;
entry->url = url; entry->url = url;

View File

@ -256,10 +256,9 @@ defaults (void)
NULL this way is technically illegal, but porting Wget to a NULL this way is technically illegal, but porting Wget to a
machine where NULL is not all-zero bit pattern will be the least machine where NULL is not all-zero bit pattern will be the least
of the implementors' worries. */ of the implementors' worries. */
memset (&opt, 0, sizeof (opt)); xzero (opt);
opt.cookies = 1; opt.cookies = 1;
opt.verbose = -1; opt.verbose = -1;
opt.ntry = 20; opt.ntry = 20;
opt.reclevel = 5; opt.reclevel = 5;

View File

@ -233,7 +233,7 @@ saved_append_1 (const char *start, const char *end)
{ {
/* Allocate memory and concatenate the old and the new /* Allocate memory and concatenate the old and the new
contents. */ contents. */
ln->malloced_line = xmalloc (old_len + len + 1); ln->malloced_line = (char *)xmalloc (old_len + len + 1);
memcpy (ln->malloced_line, ln->static_line, memcpy (ln->malloced_line, ln->static_line,
old_len); old_len);
memcpy (ln->malloced_line + old_len, start, len); memcpy (ln->malloced_line + old_len, start, len);
@ -500,7 +500,7 @@ logprintf (enum log_options o, const char *fmt, ...)
return; return;
CHECK_VERBOSE (o); CHECK_VERBOSE (o);
memset (&lpstate, '\0', sizeof (lpstate)); xzero (lpstate);
do do
{ {
VA_START (args, fmt); VA_START (args, fmt);
@ -526,7 +526,7 @@ debug_logprintf (const char *fmt, ...)
if (inhibit_logging) if (inhibit_logging)
return; return;
memset (&lpstate, '\0', sizeof (lpstate)); xzero (lpstate);
do do
{ {
VA_START (args, fmt); VA_START (args, fmt);

View File

@ -206,10 +206,7 @@ struct dot_progress {
static void * static void *
dot_create (long initial, long total) dot_create (long initial, long total)
{ {
struct dot_progress *dp = xmalloc (sizeof (struct dot_progress)); struct dot_progress *dp = xnew0 (struct dot_progress);
memset (dp, 0, sizeof (*dp));
dp->initial_length = initial; dp->initial_length = initial;
dp->total_length = total; dp->total_length = total;
@ -477,9 +474,7 @@ static void display_image PARAMS ((char *));
static void * static void *
bar_create (long initial, long total) bar_create (long initial, long total)
{ {
struct bar_progress *bp = xmalloc (sizeof (struct bar_progress)); struct bar_progress *bp = xnew0 (struct bar_progress);
memset (bp, 0, sizeof (*bp));
/* In theory, our callers should take care of this pathological /* In theory, our callers should take care of this pathological
case, but it can sometimes happen. */ case, but it can sometimes happen. */

View File

@ -87,8 +87,7 @@ struct url_queue {
static struct url_queue * static struct url_queue *
url_queue_new (void) url_queue_new (void)
{ {
struct url_queue *queue = xmalloc (sizeof (*queue)); struct url_queue *queue = xnew0 (struct url_queue);
memset (queue, '\0', sizeof (*queue));
return queue; return queue;
} }
@ -108,7 +107,7 @@ static void
url_enqueue (struct url_queue *queue, url_enqueue (struct url_queue *queue,
const char *url, const char *referer, int depth, int html_allowed) const char *url, const char *referer, int depth, int html_allowed)
{ {
struct queue_element *qel = xmalloc (sizeof (*qel)); struct queue_element *qel = xnew (struct queue_element);
qel->url = url; qel->url = url;
qel->referer = referer; qel->referer = referer;
qel->depth = depth; qel->depth = depth;
@ -605,8 +604,7 @@ descend_redirect_p (const char *redirected, const char *original, int depth,
new_parsed = url_parse (redirected, NULL); new_parsed = url_parse (redirected, NULL);
assert (new_parsed != NULL); assert (new_parsed != NULL);
upos = xmalloc (sizeof (struct urlpos)); upos = xnew0 (struct urlpos);
memset (upos, 0, sizeof (*upos));
upos->url = new_parsed; upos->url = new_parsed;
success = download_child_p (upos, orig_parsed, depth, success = download_child_p (upos, orig_parsed, depth,

View File

@ -167,7 +167,7 @@ prune_non_exact (struct robot_specs *specs)
for (i = 0; i < specs->count; i++) for (i = 0; i < specs->count; i++)
if (specs->paths[i].user_agent_exact_p) if (specs->paths[i].user_agent_exact_p)
++cnt; ++cnt;
newpaths = xmalloc (cnt * sizeof (struct path_info)); newpaths = xnew_array (struct path_info, cnt);
for (i = 0, j = 0; i < specs->count; i++) for (i = 0, j = 0; i < specs->count; i++)
if (specs->paths[i].user_agent_exact_p) if (specs->paths[i].user_agent_exact_p)
newpaths[j++] = specs->paths[i]; newpaths[j++] = specs->paths[i];
@ -240,8 +240,7 @@ res_parse (const char *source, int length)
the last `user-agent' instructions. */ the last `user-agent' instructions. */
int record_count = 0; int record_count = 0;
struct robot_specs *specs = xmalloc (sizeof (struct robot_specs)); struct robot_specs *specs = xnew0 (struct robot_specs);
memset (specs, '\0', sizeof (struct robot_specs));
while (1) while (1)
{ {

View File

@ -971,9 +971,7 @@ url_parse (const char *url, int *error)
} }
} }
u = (struct url *)xmalloc (sizeof (struct url)); u = xnew0 (struct url);
memset (u, 0, sizeof (*u));
u->scheme = scheme; u->scheme = scheme;
u->host = strdupdelim (host_b, host_e); u->host = strdupdelim (host_b, host_e);
u->port = port; u->port = port;

View File

@ -768,7 +768,7 @@ read_file (const char *file)
fd = open (file, O_RDONLY); fd = open (file, O_RDONLY);
if (fd < 0) if (fd < 0)
return NULL; return NULL;
fm = xmalloc (sizeof (struct file_memory)); fm = xnew (struct file_memory);
#ifdef HAVE_MMAP #ifdef HAVE_MMAP
{ {
@ -936,7 +936,7 @@ merge_vecs (char **v1, char **v2)
slist * slist *
slist_append (slist *l, const char *s) slist_append (slist *l, const char *s)
{ {
slist *newel = (slist *)xmalloc (sizeof (slist)); slist *newel = xnew (slist);
slist *beg = l; slist *beg = l;
newel->string = xstrdup (s); newel->string = xstrdup (s);
@ -956,7 +956,7 @@ slist_append (slist *l, const char *s)
slist * slist *
slist_prepend (slist *l, const char *s) slist_prepend (slist *l, const char *s)
{ {
slist *newel = (slist *)xmalloc (sizeof (slist)); slist *newel = xnew (slist);
newel->string = xstrdup (s); newel->string = xstrdup (s);
newel->next = l; newel->next = l;
return newel; return newel;
@ -1343,8 +1343,7 @@ struct wget_timer {
struct wget_timer * struct wget_timer *
wtimer_allocate (void) wtimer_allocate (void)
{ {
struct wget_timer *wt = struct wget_timer *wt = xnew (struct wget_timer);
(struct wget_timer *)xmalloc (sizeof (struct wget_timer));
return wt; return wt;
} }
@ -1745,7 +1744,7 @@ alarm_set (double timeout)
#ifdef ITIMER_REAL #ifdef ITIMER_REAL
/* Use the modern itimer interface. */ /* Use the modern itimer interface. */
struct itimerval itv; struct itimerval itv;
memset (&itv, 0, sizeof (itv)); xzero (itv);
itv.it_value.tv_sec = (long) timeout; itv.it_value.tv_sec = (long) timeout;
itv.it_value.tv_usec = 1000000L * (timeout - (long)timeout); itv.it_value.tv_usec = 1000000L * (timeout - (long)timeout);
if (itv.it_value.tv_sec == 0 && itv.it_value.tv_usec == 0) if (itv.it_value.tv_sec == 0 && itv.it_value.tv_usec == 0)
@ -1773,7 +1772,7 @@ alarm_cancel (void)
{ {
#ifdef ITIMER_REAL #ifdef ITIMER_REAL
struct itimerval disable; struct itimerval disable;
memset (&disable, 0, sizeof (disable)); xzero (disable);
setitimer (ITIMER_REAL, &disable, NULL); setitimer (ITIMER_REAL, &disable, NULL);
#else /* not ITIMER_REAL */ #else /* not ITIMER_REAL */
alarm (0); alarm (0);

View File

@ -118,7 +118,7 @@ so, delete this exception statement from your version. */
#define countof(array) (sizeof (array) / sizeof ((array)[0])) #define countof(array) (sizeof (array) / sizeof ((array)[0]))
/* Zero out a value. */ /* Zero out a value. */
#define xzero(x) memset (&(x), '\0', sizeof (x)) #define xzero(x) memset (&(x), '\0', sizeof ((x)))
/* Convert an ASCII hex digit to the corresponding number between 0 /* Convert an ASCII hex digit to the corresponding number between 0
and 15. X should be a hexadecimal digit that satisfies isxdigit; and 15. X should be a hexadecimal digit that satisfies isxdigit;