mirror of
https://https.git.savannah.gnu.org/git/gnulib.git
synced 2026-09-01 02:34:55 +00:00
More uses of XMALLOC, XNMALLOC and XCALLOC.
This commit is contained in:
@@ -1,3 +1,25 @@
|
||||
2006-11-07 Bruno Haible <bruno@clisp.org>
|
||||
|
||||
* lib/w32spawn.h (prepare_spawn): Use XNMALLOC instead of xmalloc.
|
||||
|
||||
2006-11-06 Paul Eggert <eggert@cs.ucla.edu>
|
||||
|
||||
Simplify xmalloc expressions. Add overflow check in xmalloc arguments.
|
||||
* lib/gl_anyavltree_list2.h (create_subtree_with_contents):
|
||||
(gl_tree_create, gl_tree_add_first, gl_tree_add_last):
|
||||
(gl_tree_add_before, gl_tree_add_after):
|
||||
Use XMALLOC instead of xmalloc, and XCALLOC instead of xzalloc.
|
||||
* lib/gl_anyhash_list2.h (hash_resize): Likewise.
|
||||
* lib/gl_anylinked_list2.h (gl_linked_create_empty, gl_linked_create):
|
||||
(gl_linked_add_first, gl_linked_add_last, gl_linked_add_before):
|
||||
(gl_linked_add_after, gl_linked_add_at): Likewise.
|
||||
* lib/gl_anyrbtree_list2.h (create_subtree_with_contents):
|
||||
(gl_tree_create, gl_tree_add_first, gl_tree_add_last):
|
||||
(gl_tree_add_before, gl_tree_add_after): Likewise.
|
||||
* lib/gl_anytree_list2.h (gl_tree_create_empty): Likewise.
|
||||
* lib/gl_anytree_oset.h (gl_tree_create_empty): Likewise.
|
||||
* lib/gl_anytreehash_list1.h (add_to_bucket): Likewise.
|
||||
|
||||
2006-11-06 Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
|
||||
|
||||
* lib/gl_oset.h: Use C comment style, not C++ comment style.
|
||||
|
||||
@@ -28,8 +28,7 @@ create_subtree_with_contents (size_t count, const void **contents)
|
||||
size_t half1 = (count - 1) / 2;
|
||||
size_t half2 = count / 2;
|
||||
/* Note: half1 + half2 = count - 1. */
|
||||
gl_list_node_t node =
|
||||
(struct gl_list_node_impl *) xmalloc (sizeof (struct gl_list_node_impl));
|
||||
gl_list_node_t node = XMALLOC (struct gl_list_node_impl);
|
||||
|
||||
if (half1 > 0)
|
||||
{
|
||||
@@ -67,8 +66,7 @@ gl_tree_create (gl_list_implementation_t implementation,
|
||||
bool allow_duplicates,
|
||||
size_t count, const void **contents)
|
||||
{
|
||||
struct gl_list_impl *list =
|
||||
(struct gl_list_impl *) xmalloc (sizeof (struct gl_list_impl));
|
||||
struct gl_list_impl *list = XMALLOC (struct gl_list_impl);
|
||||
|
||||
list->base.vtable = implementation;
|
||||
list->base.equals_fn = equals_fn;
|
||||
@@ -80,8 +78,7 @@ gl_tree_create (gl_list_implementation_t implementation,
|
||||
if (estimate < 10)
|
||||
estimate = 10;
|
||||
list->table_size = next_prime (estimate);
|
||||
list->table =
|
||||
(gl_hash_entry_t *) xzalloc (list->table_size * sizeof (gl_hash_entry_t));
|
||||
list->table = XCALLOC (list->table_size, gl_hash_entry_t);
|
||||
}
|
||||
#endif
|
||||
if (count > 0)
|
||||
@@ -374,8 +371,7 @@ static gl_list_node_t
|
||||
gl_tree_add_first (gl_list_t list, const void *elt)
|
||||
{
|
||||
/* Create new node. */
|
||||
gl_list_node_t new_node =
|
||||
(struct gl_list_node_impl *) xmalloc (sizeof (struct gl_list_node_impl));
|
||||
gl_list_node_t new_node = XMALLOC (struct gl_list_node_impl);
|
||||
|
||||
new_node->left = NULL;
|
||||
new_node->right = NULL;
|
||||
@@ -434,8 +430,7 @@ static gl_list_node_t
|
||||
gl_tree_add_last (gl_list_t list, const void *elt)
|
||||
{
|
||||
/* Create new node. */
|
||||
gl_list_node_t new_node =
|
||||
(struct gl_list_node_impl *) xmalloc (sizeof (struct gl_list_node_impl));
|
||||
gl_list_node_t new_node = XMALLOC (struct gl_list_node_impl);
|
||||
|
||||
new_node->left = NULL;
|
||||
new_node->right = NULL;
|
||||
@@ -494,8 +489,7 @@ static gl_list_node_t
|
||||
gl_tree_add_before (gl_list_t list, gl_list_node_t node, const void *elt)
|
||||
{
|
||||
/* Create new node. */
|
||||
gl_list_node_t new_node =
|
||||
(struct gl_list_node_impl *) xmalloc (sizeof (struct gl_list_node_impl));
|
||||
gl_list_node_t new_node = XMALLOC (struct gl_list_node_impl);
|
||||
bool height_inc;
|
||||
|
||||
new_node->left = NULL;
|
||||
@@ -554,8 +548,7 @@ static gl_list_node_t
|
||||
gl_tree_add_after (gl_list_t list, gl_list_node_t node, const void *elt)
|
||||
{
|
||||
/* Create new node. */
|
||||
gl_list_node_t new_node =
|
||||
(struct gl_list_node_impl *) xmalloc (sizeof (struct gl_list_node_impl));
|
||||
gl_list_node_t new_node = XMALLOC (struct gl_list_node_impl);
|
||||
bool height_inc;
|
||||
|
||||
new_node->left = NULL;
|
||||
|
||||
@@ -100,8 +100,7 @@ hash_resize (gl_list_t list, size_t estimate)
|
||||
{
|
||||
gl_hash_entry_t *old_table = list->table;
|
||||
/* Allocate the new table. */
|
||||
gl_hash_entry_t *new_table =
|
||||
(gl_hash_entry_t *) xzalloc (new_size * sizeof (gl_hash_entry_t));
|
||||
gl_hash_entry_t *new_table = XCALLOC (new_size, gl_hash_entry_t);
|
||||
size_t i;
|
||||
|
||||
/* Iterate through the entries of the old table. */
|
||||
|
||||
+10
-21
@@ -43,8 +43,7 @@ gl_linked_create_empty (gl_list_implementation_t implementation,
|
||||
gl_listelement_hashcode_fn hashcode_fn,
|
||||
bool allow_duplicates)
|
||||
{
|
||||
struct gl_list_impl *list =
|
||||
(struct gl_list_impl *) xmalloc (sizeof (struct gl_list_impl));
|
||||
struct gl_list_impl *list = XMALLOC (struct gl_list_impl);
|
||||
|
||||
list->base.vtable = implementation;
|
||||
list->base.equals_fn = equals_fn;
|
||||
@@ -52,8 +51,7 @@ gl_linked_create_empty (gl_list_implementation_t implementation,
|
||||
list->base.allow_duplicates = allow_duplicates;
|
||||
#if WITH_HASHTABLE
|
||||
list->table_size = 11;
|
||||
list->table =
|
||||
(gl_hash_entry_t *) xzalloc (list->table_size * sizeof (gl_hash_entry_t));
|
||||
list->table = XCALLOC (list->table_size, gl_hash_entry_t);
|
||||
#endif
|
||||
list->root.next = &list->root;
|
||||
list->root.prev = &list->root;
|
||||
@@ -69,8 +67,7 @@ gl_linked_create (gl_list_implementation_t implementation,
|
||||
bool allow_duplicates,
|
||||
size_t count, const void **contents)
|
||||
{
|
||||
struct gl_list_impl *list =
|
||||
(struct gl_list_impl *) xmalloc (sizeof (struct gl_list_impl));
|
||||
struct gl_list_impl *list = XMALLOC (struct gl_list_impl);
|
||||
gl_list_node_t tail;
|
||||
|
||||
list->base.vtable = implementation;
|
||||
@@ -83,17 +80,14 @@ gl_linked_create (gl_list_implementation_t implementation,
|
||||
if (estimate < 10)
|
||||
estimate = 10;
|
||||
list->table_size = next_prime (estimate);
|
||||
list->table =
|
||||
(gl_hash_entry_t *) xzalloc (list->table_size * sizeof (gl_hash_entry_t));
|
||||
list->table = XCALLOC (list->table_size, gl_hash_entry_t);
|
||||
}
|
||||
#endif
|
||||
list->count = count;
|
||||
tail = &list->root;
|
||||
for (; count > 0; contents++, count--)
|
||||
{
|
||||
gl_list_node_t node =
|
||||
(struct gl_list_node_impl *)
|
||||
xmalloc (sizeof (struct gl_list_node_impl));
|
||||
gl_list_node_t node = XMALLOC (struct gl_list_node_impl);
|
||||
|
||||
node->value = *contents;
|
||||
#if WITH_HASHTABLE
|
||||
@@ -497,8 +491,7 @@ gl_linked_indexof_from_to (gl_list_t list, size_t start_index, size_t end_index,
|
||||
static gl_list_node_t
|
||||
gl_linked_add_first (gl_list_t list, const void *elt)
|
||||
{
|
||||
gl_list_node_t node =
|
||||
(struct gl_list_node_impl *) xmalloc (sizeof (struct gl_list_node_impl));
|
||||
gl_list_node_t node = XMALLOC (struct gl_list_node_impl);
|
||||
|
||||
ASYNCSAFE(const void *) node->value = elt;
|
||||
#if WITH_HASHTABLE
|
||||
@@ -528,8 +521,7 @@ gl_linked_add_first (gl_list_t list, const void *elt)
|
||||
static gl_list_node_t
|
||||
gl_linked_add_last (gl_list_t list, const void *elt)
|
||||
{
|
||||
gl_list_node_t node =
|
||||
(struct gl_list_node_impl *) xmalloc (sizeof (struct gl_list_node_impl));
|
||||
gl_list_node_t node = XMALLOC (struct gl_list_node_impl);
|
||||
|
||||
ASYNCSAFE(const void *) node->value = elt;
|
||||
#if WITH_HASHTABLE
|
||||
@@ -559,8 +551,7 @@ gl_linked_add_last (gl_list_t list, const void *elt)
|
||||
static gl_list_node_t
|
||||
gl_linked_add_before (gl_list_t list, gl_list_node_t node, const void *elt)
|
||||
{
|
||||
gl_list_node_t new_node =
|
||||
(struct gl_list_node_impl *) xmalloc (sizeof (struct gl_list_node_impl));
|
||||
gl_list_node_t new_node = XMALLOC (struct gl_list_node_impl);
|
||||
|
||||
ASYNCSAFE(const void *) new_node->value = elt;
|
||||
#if WITH_HASHTABLE
|
||||
@@ -590,8 +581,7 @@ gl_linked_add_before (gl_list_t list, gl_list_node_t node, const void *elt)
|
||||
static gl_list_node_t
|
||||
gl_linked_add_after (gl_list_t list, gl_list_node_t node, const void *elt)
|
||||
{
|
||||
gl_list_node_t new_node =
|
||||
(struct gl_list_node_impl *) xmalloc (sizeof (struct gl_list_node_impl));
|
||||
gl_list_node_t new_node = XMALLOC (struct gl_list_node_impl);
|
||||
|
||||
ASYNCSAFE(const void *) new_node->value = elt;
|
||||
#if WITH_HASHTABLE
|
||||
@@ -628,8 +618,7 @@ gl_linked_add_at (gl_list_t list, size_t position, const void *elt)
|
||||
/* Invalid argument. */
|
||||
abort ();
|
||||
|
||||
new_node =
|
||||
(struct gl_list_node_impl *) xmalloc (sizeof (struct gl_list_node_impl));
|
||||
new_node = XMALLOC (struct gl_list_node_impl);
|
||||
ASYNCSAFE(const void *) new_node->value = elt;
|
||||
#if WITH_HASHTABLE
|
||||
new_node->h.hashcode =
|
||||
|
||||
@@ -31,8 +31,7 @@ create_subtree_with_contents (unsigned int bh,
|
||||
size_t half1 = (count - 1) / 2;
|
||||
size_t half2 = count / 2;
|
||||
/* Note: half1 + half2 = count - 1. */
|
||||
gl_list_node_t node =
|
||||
(struct gl_list_node_impl *) xmalloc (sizeof (struct gl_list_node_impl));
|
||||
gl_list_node_t node = XMALLOC (struct gl_list_node_impl);
|
||||
|
||||
if (half1 > 0)
|
||||
{
|
||||
@@ -72,8 +71,7 @@ gl_tree_create (gl_list_implementation_t implementation,
|
||||
bool allow_duplicates,
|
||||
size_t count, const void **contents)
|
||||
{
|
||||
struct gl_list_impl *list =
|
||||
(struct gl_list_impl *) xmalloc (sizeof (struct gl_list_impl));
|
||||
struct gl_list_impl *list = XMALLOC (struct gl_list_impl);
|
||||
|
||||
list->base.vtable = implementation;
|
||||
list->base.equals_fn = equals_fn;
|
||||
@@ -85,8 +83,7 @@ gl_tree_create (gl_list_implementation_t implementation,
|
||||
if (estimate < 10)
|
||||
estimate = 10;
|
||||
list->table_size = next_prime (estimate);
|
||||
list->table =
|
||||
(gl_hash_entry_t *) xzalloc (list->table_size * sizeof (gl_hash_entry_t));
|
||||
list->table = XCALLOC (list->table_size, gl_hash_entry_t);
|
||||
}
|
||||
#endif
|
||||
if (count > 0)
|
||||
@@ -599,8 +596,7 @@ static gl_list_node_t
|
||||
gl_tree_add_first (gl_list_t list, const void *elt)
|
||||
{
|
||||
/* Create new node. */
|
||||
gl_list_node_t new_node =
|
||||
(struct gl_list_node_impl *) xmalloc (sizeof (struct gl_list_node_impl));
|
||||
gl_list_node_t new_node = XMALLOC (struct gl_list_node_impl);
|
||||
|
||||
new_node->left = NULL;
|
||||
new_node->right = NULL;
|
||||
@@ -657,8 +653,7 @@ static gl_list_node_t
|
||||
gl_tree_add_last (gl_list_t list, const void *elt)
|
||||
{
|
||||
/* Create new node. */
|
||||
gl_list_node_t new_node =
|
||||
(struct gl_list_node_impl *) xmalloc (sizeof (struct gl_list_node_impl));
|
||||
gl_list_node_t new_node = XMALLOC (struct gl_list_node_impl);
|
||||
|
||||
new_node->left = NULL;
|
||||
new_node->right = NULL;
|
||||
@@ -715,8 +710,7 @@ static gl_list_node_t
|
||||
gl_tree_add_before (gl_list_t list, gl_list_node_t node, const void *elt)
|
||||
{
|
||||
/* Create new node. */
|
||||
gl_list_node_t new_node =
|
||||
(struct gl_list_node_impl *) xmalloc (sizeof (struct gl_list_node_impl));
|
||||
gl_list_node_t new_node = XMALLOC (struct gl_list_node_impl);
|
||||
|
||||
new_node->left = NULL;
|
||||
new_node->right = NULL;
|
||||
@@ -766,8 +760,7 @@ static gl_list_node_t
|
||||
gl_tree_add_after (gl_list_t list, gl_list_node_t node, const void *elt)
|
||||
{
|
||||
/* Create new node. */
|
||||
gl_list_node_t new_node =
|
||||
(struct gl_list_node_impl *) xmalloc (sizeof (struct gl_list_node_impl));
|
||||
gl_list_node_t new_node = XMALLOC (struct gl_list_node_impl);
|
||||
|
||||
new_node->left = NULL;
|
||||
new_node->right = NULL;
|
||||
|
||||
@@ -25,8 +25,7 @@ gl_tree_create_empty (gl_list_implementation_t implementation,
|
||||
gl_listelement_hashcode_fn hashcode_fn,
|
||||
bool allow_duplicates)
|
||||
{
|
||||
struct gl_list_impl *list =
|
||||
(struct gl_list_impl *) xmalloc (sizeof (struct gl_list_impl));
|
||||
struct gl_list_impl *list = XMALLOC (struct gl_list_impl);
|
||||
|
||||
list->base.vtable = implementation;
|
||||
list->base.equals_fn = equals_fn;
|
||||
@@ -34,8 +33,7 @@ gl_tree_create_empty (gl_list_implementation_t implementation,
|
||||
list->base.allow_duplicates = allow_duplicates;
|
||||
#if WITH_HASHTABLE
|
||||
list->table_size = 11;
|
||||
list->table =
|
||||
(gl_hash_entry_t *) xzalloc (list->table_size * sizeof (gl_hash_entry_t));
|
||||
list->table = XCALLOC (list->table_size, gl_hash_entry_t);
|
||||
#endif
|
||||
list->root = NULL;
|
||||
|
||||
|
||||
@@ -32,8 +32,7 @@ static gl_oset_t
|
||||
gl_tree_create_empty (gl_oset_implementation_t implementation,
|
||||
gl_setelement_compar_fn compar_fn)
|
||||
{
|
||||
struct gl_oset_impl *set =
|
||||
(struct gl_oset_impl *) xmalloc (sizeof (struct gl_oset_impl));
|
||||
struct gl_oset_impl *set = XMALLOC (struct gl_oset_impl);
|
||||
|
||||
set->base.vtable = implementation;
|
||||
set->base.compar_fn = compar_fn;
|
||||
|
||||
@@ -157,8 +157,7 @@ add_to_bucket (gl_list_t list, gl_list_node_t new_node)
|
||||
gl_oset_add (nodes, node);
|
||||
gl_oset_add (nodes, new_node);
|
||||
|
||||
multi_entry =
|
||||
(struct gl_multiple_nodes *) xmalloc (sizeof (struct gl_multiple_nodes));
|
||||
multi_entry = XMALLOC (struct gl_multiple_nodes);
|
||||
multi_entry->h.hash_next = entry->hash_next;
|
||||
multi_entry->h.hashcode = entry->hashcode;
|
||||
multi_entry->magic = MULTIPLE_NODES_MAGIC;
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/* Auxiliary functions for the creation of subprocesses. Native Woe32 API.
|
||||
Copyright (C) 2003 Free Software Foundation, Inc.
|
||||
Copyright (C) 2003, 2006 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible <bruno@clisp.org>, 2003.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
@@ -92,7 +92,7 @@ prepare_spawn (char **argv)
|
||||
;
|
||||
|
||||
/* Allocate new argument vector. */
|
||||
new_argv = (char **) xmalloc ((argc + 1) * sizeof (char *));
|
||||
new_argv = XNMALLOC (argc + 1, char *);
|
||||
|
||||
/* Put quoted arguments into the new argument vector. */
|
||||
for (i = 0; i < argc; i++)
|
||||
|
||||
Reference in New Issue
Block a user