[PING][PATCH v2 2/2] Use nmalloc and nrealloc
Ondřej Bílka
neleai@seznam.cz
Wed Nov 27 21:34:00 GMT 2013
ping
On Sun, Nov 03, 2013 at 06:01:35PM +0100, OndÅej BÃlka wrote:
> On Sun, Nov 03, 2013 at 05:54:11PM +0100, OndÅej BÃlka wrote:
> > Hi,
> >
> > This patches cover more cases than previous patch. As a first part we
> > define nmalloc macros.
> >
> A second part does refactoring by coccinelle, this time we also cover
> realloc and recognize more cases. A generator is attached.
>
>
> nptl/ChangeLog:
>
> * tst-cancel20.c (do_one_test): Use nmalloc instead malloc.
> * tst-cancel21.c (do_one_test): Likewise.
> * tst-signal6.c (tf): Likewise.
>
> ChangeLog:
>
> * argp/argp-help.c (make_hol, hol_append): Use nmalloc instead malloc.
> * dirent/scandirat.c (SCANDIRAT): Likewise.
> * elf/dl-load.c (decompose_rpath, _dl_init_paths, _dl_init_paths,
> _dl_init_paths): Likewise.
> * elf/dl-open.c (add_to_global, add_to_global): Likewise.
> * elf/dl-tls.c (_dl_update_slotinfo): Likewise.
> * grp/initgroups.c (internal_getgrouplist, initgroups): Likewise.
> * hesiod/nss_hesiod/hesiod-grp.c
> (_nss_hesiod_initgroups_dyn): Likewise.
> * hurd/alloc-fd.c (_hurd_alloc_fd): Likewise.
> * hurd/hurdmsg.c (_S_msg_set_environment): Likewise.
> * hurd/hurdsig.c (_hurdsig_init): Likewise.
> * hurd/hurdsock.c (_hurd_socket_server): Likewise.
> * iconv/gconv_cache.c (__gconv_lookup_cache,
> __gconv_lookup_cache): Likewise.
> * libio/tst-mmap2-eofsync.c (): Likewise.
> * libio/wgenops.c (_IO_wdefault_pbackfail, _IO_wdefault_pbackfail,
> save_for_wbackup): Likewise.
> * malloc/malloc.c: Likewise.
> * malloc/tst-malloc.c (main): Likewise.
> * misc/err.c (convert_and_print): Likewise.
> * nis/nis_call.c (get_ckey): Likewise.
> * nis/nis_findserv.c (__nis_findfastest_with_timeout,
> __nis_findfastest_with_timeout): Likewise.
> * nis/nis_getservlist.c (nis_getservlist, nis_getservlist): Likewise.
> * nis/nis_subr.c (nis_getnames): Likewise.
> * nis/nis_table.c (__create_ib_request, nis_list): Likewise.
> * nis/nss_compat/compat-initgroups.c (add_group,
> getgrent_next_nss): Likewise.
> * nis/nss_nis/nis-initgroups.c (initgroups_netid,
> _nss_nis_initgroups_dyn): Likewise.
> * nis/nss_nisplus/nisplus-initgroups.c
> (_nss_nisplus_initgroups_dyn): Likewise.
> * nscd/initgrcache.c (addinitgroupsX): Likewise.
> * nscd/nscd_getserv_r.c (nscd_getserv_r, nscd_getserv_r): Likewise.
> * nscd/nscd_initgroups.c (__nscd_getgrouplist): Likewise.
> * posix/fnmatch.c (fnmatch, fnmatch): Likewise.
> * posix/regexec.c (build_trtable): Likewise.
> * posix/regex_internal.h (struct): Likewise.
> * posix/spawn_faction_init.c (): Likewise.
> * posix/tst-mmap.c (main): Likewise.
> * posix/wordexp.c (w_addword): Likewise.
> * resolv/gai_misc.c (get_elem): Likewise.
> * stdlib/tst-qsort2.c (compare): Likewise.
> * stdlib/tst-qsort.c (compare): Likewise.
> * string/strcoll_l.c (STRCOLL): Likewise.
> * string/strxfrm_l.c (STRXFRM): Likewise.
> * sunrpc/auth_unix.c (authunix_create_default): Likewise.
> * sunrpc/svc.c (xprt_register): Likewise.
> * sunrpc/svc_run.c (svc_run): Likewise.
> * sysdeps/gnu/ifaddrs.c (getifaddrs): Likewise.
> * sysdeps/mach/hurd/i386/init-first.c (init): Likewise.
> * sysdeps/mach/hurd/if_index.c (if_nameindex): Likewise.
> * sysdeps/posix/getaddrinfo.c (gaih_inet, gaih_inet, gaiconf_init,
> gaiconf_init, gaiconf_init): Likewise.
> * sysdeps/posix/sprofil.c (insert): Likewise.
> * sysdeps/pthread/aio_misc.c (get_elem): Likewise.
> * sysdeps/unix/ifreq.c (__ifreq): Likewise.
> * sysdeps/unix/sysv/linux/if_index.c (if_nameindex_netlink): Likewise.
> * sysdeps/unix/sysv/linux/ifreq.c (__ifreq): Likewise.
> * time/alt_digit.c (_nl_init_alt_digit, _nl_get_walt_digit): Likewise.
>
> libidn/ChangeLog:
>
> * idna.c (idna_to_ascii_4i, idna_to_unicode_4z4z): Use nmalloc instead malloc.
> * stringprep.c (stringprep): Likewise.
>
>
>
> ---
> argp/argp-help.c | 5 +++--
> dirent/scandirat.c | 3 ++-
> elf/dl-load.c | 18 +++++++++---------
> elf/dl-open.c | 7 +++----
> elf/dl-tls.c | 3 ++-
> grp/initgroups.c | 5 +++--
> hesiod/nss_hesiod/hesiod-grp.c | 3 ++-
> hurd/alloc-fd.c | 3 ++-
> hurd/hurdmsg.c | 3 ++-
> hurd/hurdsig.c | 3 ++-
> hurd/hurdsock.c | 3 ++-
> iconv/gconv_cache.c | 6 +++---
> libidn/idna.c | 5 +++--
> libidn/stringprep.c | 3 ++-
> libio/tst-mmap2-eofsync.c | 3 ++-
> libio/wgenops.c | 9 ++++-----
> malloc/malloc.c | 1 +
> malloc/tst-malloc.c | 5 +++--
> misc/err.c | 3 ++-
> nis/nis_call.c | 3 ++-
> nis/nis_findserv.c | 6 +++---
> nis/nis_getservlist.c | 7 ++++---
> nis/nis_subr.c | 3 ++-
> nis/nis_table.c | 10 +++++-----
> nis/nss_compat/compat-initgroups.c | 5 +++--
> nis/nss_nis/nis-initgroups.c | 5 +++--
> nis/nss_nisplus/nisplus-initgroups.c | 3 ++-
> nptl/tst-cancel20.c | 3 ++-
> nptl/tst-cancel21.c | 3 ++-
> nptl/tst-signal6.c | 3 ++-
> nscd/initgrcache.c | 3 ++-
> nscd/nscd_getserv_r.c | 6 +++---
> nscd/nscd_initgroups.c | 4 ++--
> posix/annexc.c | 5 +++--
> posix/fnmatch.c | 5 +++--
> posix/regex_internal.h | 4 ++--
> posix/regexec.c | 4 ++--
> posix/spawn_faction_init.c | 5 +++--
> posix/tst-mmap.c | 3 ++-
> posix/wordexp.c | 3 ++-
> resolv/gai_misc.c | 4 ++--
> stdlib/isomac.c | 5 +++--
> stdlib/tst-qsort.c | 3 ++-
> stdlib/tst-qsort2.c | 3 ++-
> string/strcoll_l.c | 4 +++-
> string/strxfrm_l.c | 3 ++-
> sunrpc/auth_unix.c | 3 ++-
> sunrpc/svc.c | 3 ++-
> sunrpc/svc_run.c | 3 ++-
> sysdeps/gnu/ifaddrs.c | 3 ++-
> sysdeps/mach/hurd/i386/init-first.c | 3 ++-
> sysdeps/mach/hurd/if_index.c | 3 ++-
> sysdeps/posix/getaddrinfo.c | 13 ++++++-------
> sysdeps/posix/sprofil.c | 3 ++-
> sysdeps/pthread/aio_misc.c | 4 ++--
> sysdeps/unix/ifreq.c | 3 ++-
> sysdeps/unix/sysv/linux/if_index.c | 3 ++-
> sysdeps/unix/sysv/linux/ifreq.c | 3 ++-
> time/alt_digit.c | 5 +++--
> 59 files changed, 151 insertions(+), 107 deletions(-)
>
> diff --git a/argp/argp-help.c b/argp/argp-help.c
> index ace71b4..af3e4ee 100644
> --- a/argp/argp-help.c
> +++ b/argp/argp-help.c
> @@ -40,6 +40,7 @@ char *alloca ();
> # endif
> #endif
>
> +#include <nmalloc.h>
> #include <stdbool.h>
> #include <stddef.h>
> #include <stdlib.h>
> @@ -454,7 +455,7 @@ make_hol (const struct argp *argp, struct hol_cluster *cluster)
> num_short_options++; /* This is an upper bound. */
> }
>
> - hol->entries = malloc (sizeof (struct hol_entry) * hol->num_entries);
> + hol->entries = NMALLOC (hol->num_entries, struct hol_entry);
> hol->short_options = malloc (num_short_options + 1);
>
> assert (hol->entries && hol->short_options);
> @@ -848,7 +849,7 @@ hol_append (struct hol *hol, struct hol *more)
> struct hol_entry *e;
> unsigned num_entries = hol->num_entries + more->num_entries;
> struct hol_entry *entries =
> - malloc (num_entries * sizeof (struct hol_entry));
> + NMALLOC (num_entries, struct hol_entry);
> unsigned hol_so_len = strlen (hol->short_options);
> char *short_options =
> malloc (hol_so_len + strlen (more->short_options) + 1);
> diff --git a/dirent/scandirat.c b/dirent/scandirat.c
> index 0f2a440..498acb2 100644
> --- a/dirent/scandirat.c
> +++ b/dirent/scandirat.c
> @@ -20,6 +20,7 @@
> complain about the mismatch when we do the alias below. */
> #define scandirat64 __renamed_scandirat64
>
> +#include <nmalloc.h>
> #include <dirent.h>
>
> #undef scandirat64
> @@ -105,7 +106,7 @@ SCANDIRAT (dfd, dir, namelist, select, cmp)
> vsize = 10;
> else
> vsize *= 2;
> - new = (DIRENT_TYPE **) realloc (v, vsize * sizeof (*v));
> + new = (DIRENT_TYPE **) nrealloc (v, vsize, sizeof (*v));
> if (new == NULL)
> break;
> v = new;
> diff --git a/elf/dl-load.c b/elf/dl-load.c
> index 6a73f27..922d3b3 100644
> --- a/elf/dl-load.c
> +++ b/elf/dl-load.c
> @@ -16,6 +16,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <elf.h>
> #include <errno.h>
> #include <fcntl.h>
> @@ -650,8 +651,8 @@ decompose_rpath (struct r_search_path_struct *sps,
>
> /* Allocate room for the result. NELEMS + 1 is an upper limit for the
> number of necessary entries. */
> - result = (struct r_search_path_elem **) malloc ((nelems + 1 + 1)
> - * sizeof (*result));
> + result = (struct r_search_path_elem **) nmalloc ((nelems + 1 + 1),
> + sizeof (*result));
> if (result == NULL)
> {
> free (copy);
> @@ -722,8 +723,8 @@ _dl_init_paths (const char *llp)
> &ncapstr, &max_capstrlen);
>
> /* First set up the rest of the default search directory entries. */
> - aelem = rtld_search_dirs.dirs = (struct r_search_path_elem **)
> - malloc ((nsystem_dirs_len + 1) * sizeof (struct r_search_path_elem *));
> + aelem = rtld_search_dirs.dirs = NMALLOC ((nsystem_dirs_len + 1),
> + struct r_search_path_elem *);
> if (rtld_search_dirs.dirs == NULL)
> {
> errstring = N_("cannot create search path array");
> @@ -735,9 +736,9 @@ _dl_init_paths (const char *llp)
> + ncapstr * sizeof (enum r_dir_status))
> / sizeof (struct r_search_path_elem));
>
> - rtld_search_dirs.dirs[0] = (struct r_search_path_elem *)
> - malloc ((sizeof (system_dirs) / sizeof (system_dirs[0]))
> - * round_size * sizeof (struct r_search_path_elem));
> + rtld_search_dirs.dirs[0] = NMALLOC ((sizeof (system_dirs)
> + / sizeof (system_dirs[0])) * round_size,
> + struct r_search_path_elem);
> if (rtld_search_dirs.dirs[0] == NULL)
> {
> errstring = N_("cannot create cache for search path");
> @@ -855,8 +856,7 @@ _dl_init_paths (const char *llp)
> ++cp;
> }
>
> - env_path_list.dirs = (struct r_search_path_elem **)
> - malloc ((nllp + 1) * sizeof (struct r_search_path_elem *));
> + env_path_list.dirs = NMALLOC ((nllp + 1), struct r_search_path_elem *);
> if (env_path_list.dirs == NULL)
> {
> errstring = N_("cannot create cache for search path");
> diff --git a/elf/dl-open.c b/elf/dl-open.c
> index 1403c8c..d18921b 100644
> --- a/elf/dl-open.c
> +++ b/elf/dl-open.c
> @@ -16,6 +16,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <assert.h>
> #include <dlfcn.h>
> #include <errno.h>
> @@ -92,8 +93,7 @@ add_to_global (struct link_map *new)
> /* This is the first dynamic object given global scope. */
> ns->_ns_global_scope_alloc
> = ns->_ns_main_searchlist->r_nlist + to_add + 8;
> - new_global = (struct link_map **)
> - malloc (ns->_ns_global_scope_alloc * sizeof (struct link_map *));
> + new_global = NMALLOC (ns->_ns_global_scope_alloc, struct link_map *);
> if (new_global == NULL)
> {
> ns->_ns_global_scope_alloc = 0;
> @@ -118,8 +118,7 @@ add_to_global (struct link_map *new)
> = GL(dl_ns)[new->l_ns]._ns_main_searchlist->r_list;
> size_t new_nalloc = ((ns->_ns_global_scope_alloc + to_add) * 2);
>
> - new_global = (struct link_map **)
> - malloc (new_nalloc * sizeof (struct link_map *));
> + new_global = NMALLOC (new_nalloc, struct link_map *);
> if (new_global == NULL)
> goto nomem;
>
> diff --git a/elf/dl-tls.c b/elf/dl-tls.c
> index 576d9a1..887ec56 100644
> --- a/elf/dl-tls.c
> +++ b/elf/dl-tls.c
> @@ -16,6 +16,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <assert.h>
> #include <errno.h>
> #include <libintl.h>
> @@ -631,7 +632,7 @@ _dl_update_slotinfo (unsigned long int req_modid)
> malloc instead of the real malloc. We can't
> free it, we have to abandon the old storage. */
>
> - newp = malloc ((2 + newsize) * sizeof (dtv_t));
> + newp = NMALLOC ((2 + newsize), dtv_t);
> if (newp == NULL)
> oom ();
> memcpy (newp, &dtv[-1], (2 + oldsize) * sizeof (dtv_t));
> diff --git a/grp/initgroups.c b/grp/initgroups.c
> index 932d8fb..0cef050 100644
> --- a/grp/initgroups.c
> +++ b/grp/initgroups.c
> @@ -15,6 +15,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <alloca.h>
> #include <assert.h>
> #include <errno.h>
> @@ -158,7 +159,7 @@ getgrouplist (const char *user, gid_t group, gid_t *groups, int *ngroups)
> {
> long int size = MAX (1, *ngroups);
>
> - gid_t *newgroups = (gid_t *) malloc (size * sizeof (gid_t));
> + gid_t *newgroups = NMALLOC (size, gid_t);
> if (__builtin_expect (newgroups == NULL, 0))
> /* No more memory. */
> // XXX This is wrong. The user provided memory, we have to use
> @@ -211,7 +212,7 @@ initgroups (const char *user, gid_t group)
> /* No fixed limit on groups. Pick a starting buffer size. */
> size = 16;
>
> - groups = (gid_t *) malloc (size * sizeof (gid_t));
> + groups = NMALLOC (size, gid_t);
> if (__builtin_expect (groups == NULL, 0))
> /* No more memory. */
> return -1;
> diff --git a/hesiod/nss_hesiod/hesiod-grp.c b/hesiod/nss_hesiod/hesiod-grp.c
> index b11952f..1276f33 100644
> --- a/hesiod/nss_hesiod/hesiod-grp.c
> +++ b/hesiod/nss_hesiod/hesiod-grp.c
> @@ -16,6 +16,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <ctype.h>
> #include <errno.h>
> #include <grp.h>
> @@ -242,7 +243,7 @@ _nss_hesiod_initgroups_dyn (const char *user, gid_t group, long int *start,
> else
> newsize = MIN (limit, 2 * *size);
>
> - newgroups = realloc (groups, newsize * sizeof (*groups));
> + newgroups = nrealloc (groups, newsize, sizeof (*groups));
> if (newgroups == NULL)
> goto done;
> *groupsp = groups = newgroups;
> diff --git a/hurd/alloc-fd.c b/hurd/alloc-fd.c
> index ec7b50a..bad042e 100644
> --- a/hurd/alloc-fd.c
> +++ b/hurd/alloc-fd.c
> @@ -15,6 +15,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <hurd.h>
> #include <hurd/fd.h>
> #include <hurd/resource.h>
> @@ -106,7 +107,7 @@ _hurd_alloc_fd (int *fd, int first_fd)
> /* If we fail to allocate that, decrement the desired size
> until we succeed in allocating it. */
> do
> - new = realloc (_hurd_dtable, size * sizeof (*_hurd_dtable));
> + new = nrealloc (_hurd_dtable, size, sizeof (*_hurd_dtable));
> while (new == NULL && size-- > first_fd);
>
> if (new != NULL)
> diff --git a/hurd/hurdmsg.c b/hurd/hurdmsg.c
> index 6e350ee..e17177c 100644
> --- a/hurd/hurdmsg.c
> +++ b/hurd/hurdmsg.c
> @@ -15,6 +15,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <hurd.h>
> #include <hurd/msg_server.h>
> #include <hurd/fd.h>
> @@ -392,7 +393,7 @@ _S_msg_set_environment (mach_port_t msgport, mach_port_t auth,
> AUTHCHECK;
>
> envc = __argz_count (data, datalen);
> - envp = malloc ((envc + 1) * sizeof (char *));
> + envp = NMALLOC ((envc + 1), char *);
> if (envp == NULL)
> return errno;
> __argz_extract (data, datalen, envp);
> diff --git a/hurd/hurdsig.c b/hurd/hurdsig.c
> index 558aa07..b3a3e61 100644
> --- a/hurd/hurdsig.c
> +++ b/hurd/hurdsig.c
> @@ -15,6 +15,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> @@ -1269,7 +1270,7 @@ _hurdsig_init (const int *intarray, size_t intarraysize)
>
> __hurd_sigthread_stack_end = __hurd_sigthread_stack_base + stacksize;
> __hurd_sigthread_variables =
> - malloc (__hurd_threadvar_max * sizeof (unsigned long int));
> + NMALLOC (__hurd_threadvar_max, unsigned long int);
> if (__hurd_sigthread_variables == NULL)
> __libc_fatal ("hurd: Can't allocate threadvars for signal thread\n");
> memset (__hurd_sigthread_variables, 0,
> diff --git a/hurd/hurdsock.c b/hurd/hurdsock.c
> index 7464f99..81b28a8 100644
> --- a/hurd/hurdsock.c
> +++ b/hurd/hurdsock.c
> @@ -16,6 +16,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <hurd.h>
> #include <sys/socket.h>
> #include <stdlib.h>
> @@ -58,7 +59,7 @@ _hurd_socket_server (int domain, int dead)
> if (domain > max_domain)
> {
> error_t save = errno;
> - file_t *new = realloc (servers, (domain + 1) * sizeof (file_t));
> + file_t *new = NREALLOC (servers, (domain + 1), file_t);
> if (new != NULL)
> {
> do
> diff --git a/iconv/gconv_cache.c b/iconv/gconv_cache.c
> index ccd2d6e..75cc0f1 100644
> --- a/iconv/gconv_cache.c
> +++ b/iconv/gconv_cache.c
> @@ -17,6 +17,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <dlfcn.h>
> #include <errno.h>
> #include <fcntl.h>
> @@ -314,8 +315,7 @@ __gconv_lookup_cache (const char *toset, const char *fromset,
>
> *nsteps = extra->module_cnt;
> *handle = result =
> - (struct __gconv_step *) malloc (extra->module_cnt
> - * sizeof (struct __gconv_step));
> + NMALLOC (extra->module_cnt, struct __gconv_step);
> if (result == NULL)
> return __GCONV_NOMEM;
>
> @@ -369,7 +369,7 @@ __gconv_lookup_cache (const char *toset, const char *fromset,
> return __GCONV_NOCONV;
>
> /* We will use up to two modules. Always allocate room for two. */
> - result = (struct __gconv_step *) malloc (2 * sizeof (struct __gconv_step));
> + result = NMALLOC (2, struct __gconv_step);
> if (result == NULL)
> return __GCONV_NOMEM;
>
> diff --git a/libidn/idna.c b/libidn/idna.c
> index 7a15a25..7612d62 100644
> --- a/libidn/idna.c
> +++ b/libidn/idna.c
> @@ -21,6 +21,7 @@
> # include "config.h"
> #endif
>
> +#include <nmalloc.h>
> #include <stdlib.h>
> #include <string.h>
> #include <stringprep.h>
> @@ -88,7 +89,7 @@ idna_to_ascii_4i (const uint32_t * in, size_t inlen, char *out, int flags)
> inasciirange = 0;
> if (inasciirange)
> {
> - src = malloc (sizeof (in[0]) * (inlen + 1));
> + src = nmalloc (sizeof (in[0]), (inlen + 1));
> if (src == NULL)
> return IDNA_MALLOC_ERROR;
>
> @@ -624,7 +625,7 @@ idna_to_unicode_4z4z (const uint32_t * input, uint32_t ** output, int flags)
> ;
>
> buflen = end - start;
> - buf = malloc (sizeof (buf[0]) * (buflen + 1));
> + buf = nmalloc (sizeof (buf[0]), (buflen + 1));
> if (!buf)
> return IDNA_MALLOC_ERROR;
>
> diff --git a/libidn/stringprep.c b/libidn/stringprep.c
> index 72a502e..1deffa1 100644
> --- a/libidn/stringprep.c
> +++ b/libidn/stringprep.c
> @@ -21,6 +21,7 @@
> # include "config.h"
> #endif
>
> +#include <nmalloc.h>
> #include <stdlib.h>
> #include <string.h>
> #include <stdint.h>
> @@ -368,7 +369,7 @@ stringprep (char *in,
> free (ucs4);
> ucs4 = stringprep_utf8_to_ucs4 (in, -1, &ucs4len);
> maxucs4len = ucs4len + adducs4len;
> - uint32_t *newp = realloc (ucs4, maxucs4len * sizeof (uint32_t));
> + uint32_t *newp = NREALLOC (ucs4, maxucs4len, uint32_t);
> if (!newp)
> {
> free (ucs4);
> diff --git a/libio/tst-mmap2-eofsync.c b/libio/tst-mmap2-eofsync.c
> index f369965..4c26658 100644
> --- a/libio/tst-mmap2-eofsync.c
> +++ b/libio/tst-mmap2-eofsync.c
> @@ -1,5 +1,6 @@
> /* Test program for synchronization of stdio state with file after EOF. */
>
> +#include <nmalloc.h>
> #include <stdio.h>
> #include <error.h>
> #include <errno.h>
> @@ -20,7 +21,7 @@ static char *pages;
> static void
> do_prepare (void)
> {
> - pages = malloc (getpagesize () * 2);
> + pages = nmalloc (getpagesize (), 2);
> memset (pages, 'a', getpagesize ());
> memset (pages + getpagesize (), 'b', getpagesize ());
>
> diff --git a/libio/wgenops.c b/libio/wgenops.c
> index b39b691..32fdf0a 100644
> --- a/libio/wgenops.c
> +++ b/libio/wgenops.c
> @@ -28,6 +28,7 @@
>
> /* Generic or default I/O operations. */
>
> +#include <nmalloc.h>
> #include "libioP.h"
> #include <stdlib.h>
> #include <string.h>
> @@ -149,8 +150,7 @@ _IO_wdefault_pbackfail (fp, c)
> /* No backup buffer: allocate one. */
> /* Use nshort buffer, if unused? (probably not) FIXME */
> int backup_size = 128;
> - wchar_t *bbuf = (wchar_t *) malloc (backup_size
> - * sizeof (wchar_t));
> + wchar_t *bbuf = NMALLOC (backup_size, wchar_t);
> if (bbuf == NULL)
> return WEOF;
> fp->_wide_data->_IO_save_base = bbuf;
> @@ -169,7 +169,7 @@ _IO_wdefault_pbackfail (fp, c)
> - fp->_wide_data->_IO_read_base);
> wchar_t *new_buf;
> new_size = 2 * old_size;
> - new_buf = (wchar_t *) malloc (new_size * sizeof (wchar_t));
> + new_buf = NMALLOC (new_size, wchar_t);
> if (new_buf == NULL)
> return WEOF;
> __wmemcpy (new_buf + (new_size - old_size),
> @@ -515,8 +515,7 @@ save_for_wbackup (fp, end_p)
> {
> wchar_t *new_buffer;
> avail = 100;
> - new_buffer = (wchar_t *) malloc ((avail + needed_size)
> - * sizeof (wchar_t));
> + new_buffer = NMALLOC ((avail + needed_size), wchar_t);
> if (new_buffer == NULL)
> return EOF; /* FIXME */
> if (least_mark < 0)
> diff --git a/malloc/malloc.c b/malloc/malloc.c
> index 897c43a..1452d84 100644
> --- a/malloc/malloc.c
> +++ b/malloc/malloc.c
> @@ -212,6 +212,7 @@
> #define void void
> #endif /*void*/
>
> +#include <nmalloc.h>
> #include <stddef.h> /* for size_t */
> #include <stdlib.h> /* for getenv(), abort() */
> #include <unistd.h> /* for __libc_enable_secure */
> diff --git a/malloc/tst-malloc.c b/malloc/tst-malloc.c
> index 518c8e5..482d3db 100644
> --- a/malloc/tst-malloc.c
> +++ b/malloc/tst-malloc.c
> @@ -16,6 +16,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <errno.h>
> #include <malloc.h>
> #include <stdio.h>
> @@ -63,11 +64,11 @@ main (void)
> if (p != NULL)
> merror ("realloc (p, 0) failed.");
>
> - p = malloc (513 * 1024);
> + p = nmalloc (513, 1024);
> if (p == NULL)
> merror ("malloc (513K) failed.");
>
> - q = malloc (-512 * 1024);
> + q = nmalloc (-512, 1024);
> if (q != NULL)
> merror ("malloc (-512K) succeeded.");
>
> diff --git a/misc/err.c b/misc/err.c
> index e082a8b..ad6d6db 100644
> --- a/misc/err.c
> +++ b/misc/err.c
> @@ -16,6 +16,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <stdarg.h>
> #include <err.h>
> #include <stdlib.h>
> @@ -61,7 +62,7 @@ convert_and_print (const char *format, __gnuc_va_list ap)
> if (wformat != NULL && len / 2 < ALLOCA_LIMIT)
> wformat = NULL;
>
> - wformat = (wchar_t *) realloc (wformat, len * sizeof (wchar_t));
> + wformat = NREALLOC (wformat, len, wchar_t);
>
> if (wformat == NULL)
> {
> diff --git a/nis/nis_call.c b/nis/nis_call.c
> index b97f8a1..d311ce4 100644
> --- a/nis/nis_call.c
> +++ b/nis/nis_call.c
> @@ -16,6 +16,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <errno.h>
> #include <fcntl.h>
> #include <string.h>
> @@ -160,7 +161,7 @@ get_ckey (des_block *ckey, struct sockaddr_in *addr, unsigned int protocol)
> {
> size_t size = ckey_cache_allocated ? ckey_cache_allocated * 2 : 16;
> struct ckey_cache_entry *new_cache
> - = realloc (ckey_cache, size * sizeof (*ckey_cache));
> + = nrealloc (ckey_cache, size, sizeof (*ckey_cache));
> if (new_cache != NULL)
> {
> ckey_cache = new_cache;
> diff --git a/nis/nis_findserv.c b/nis/nis_findserv.c
> index c5269c2..deb1788 100644
> --- a/nis/nis_findserv.c
> +++ b/nis/nis_findserv.c
> @@ -16,6 +16,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <string.h>
> #include <time.h>
> #include <unistd.h>
> @@ -86,7 +87,7 @@ __nis_findfastest_with_timeout (dir_binding *bind,
> pings_max = bind->server_len * 2; /* Reserve a little bit more memory
> for multihomed hosts */
> pings_count = 0;
> - pings = malloc (sizeof (struct findserv_req) * pings_max);
> + pings = NMALLOC (pings_max, struct findserv_req);
> xid_seed = (u_int32_t) (time (NULL) ^ getpid ());
>
> if (__builtin_expect (pings == NULL, 0))
> @@ -116,8 +117,7 @@ __nis_findfastest_with_timeout (dir_binding *bind,
> struct findserv_req *new_pings;
>
> pings_max += 10;
> - new_pings = realloc (pings, sizeof (struct findserv_req) *
> - pings_max);
> + new_pings = NREALLOC (pings, pings_max, struct findserv_req);
> if (__builtin_expect (new_pings == NULL, 0))
> {
> free (pings);
> diff --git a/nis/nis_getservlist.c b/nis/nis_getservlist.c
> index 54840ab..8b16bb4 100644
> --- a/nis/nis_getservlist.c
> +++ b/nis/nis_getservlist.c
> @@ -16,6 +16,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <string.h>
> #include <rpcsvc/nis.h>
>
> @@ -36,8 +37,8 @@ nis_getservlist (const_nis_name dir)
> nis_server *server;
>
> serv =
> - malloc (sizeof (nis_server *) *
> - (NIS_RES_OBJECT (res)->DI_data.do_servers.do_servers_len + 1));
> + NMALLOC ((NIS_RES_OBJECT (res)->DI_data.do_servers.do_servers_len + 1),
> + nis_server *);
> if (__builtin_expect (serv == NULL, 0))
> {
> nis_freeresult (res);
> @@ -94,7 +95,7 @@ nis_getservlist (const_nis_name dir)
> unsigned long int j;
>
> serv[i]->ep.ep_val =
> - malloc (server->ep.ep_len * sizeof (endpoint));
> + nmalloc (server->ep.ep_len, sizeof (endpoint));
> if (__builtin_expect (serv[i]->ep.ep_val == NULL, 0))
> {
> ++i;
> diff --git a/nis/nis_subr.c b/nis/nis_subr.c
> index a03600d..13060ea 100644
> --- a/nis/nis_subr.c
> +++ b/nis/nis_subr.c
> @@ -16,6 +16,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <errno.h>
> #include <string.h>
> #include <rpcsvc/nis.h>
> @@ -117,7 +118,7 @@ nis_getnames (const_nis_name name)
> const char *cp2;
>
> int count = 2;
> - nis_name *getnames = malloc ((count + 1) * sizeof (char *));
> + nis_name *getnames = NMALLOC ((count + 1), char *);
> if (__builtin_expect (getnames == NULL, 0))
> return NULL;
>
> diff --git a/nis/nis_table.c b/nis/nis_table.c
> index 0ca40db..bd37fb0 100644
> --- a/nis/nis_table.c
> +++ b/nis/nis_table.c
> @@ -16,6 +16,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <assert.h>
> #include <string.h>
> #include <rpcsvc/nis.h>
> @@ -101,7 +102,7 @@ __create_ib_request (const_nis_name name, unsigned int flags)
> if (search_len + 1 >= size)
> {
> size += 1;
> - nis_attr *newp = realloc (search_val, size * sizeof (nis_attr));
> + nis_attr *newp = NREALLOC (search_val, size, nis_attr);
> if (newp == NULL)
> goto free_null;
> search_val = newp;
> @@ -406,10 +407,9 @@ nis_list (const_nis_name name, unsigned int flags,
> else
> {
> nis_object *objects_val
> - = realloc (NIS_RES_OBJECT (allres),
> - (NIS_RES_NUMOBJ (allres)
> - + NIS_RES_NUMOBJ (res))
> - * sizeof (nis_object));
> + = NREALLOC (NIS_RES_OBJECT (allres),
> + (NIS_RES_NUMOBJ (allres) + NIS_RES_NUMOBJ (res)),
> + nis_object);
> if (objects_val == NULL)
> {
> NIS_RES_STATUS (res) = NIS_NOMEMORY;
> diff --git a/nis/nss_compat/compat-initgroups.c b/nis/nss_compat/compat-initgroups.c
> index cf924c4..498bfe4 100644
> --- a/nis/nss_compat/compat-initgroups.c
> +++ b/nis/nss_compat/compat-initgroups.c
> @@ -16,6 +16,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <alloca.h>
> #include <ctype.h>
> #include <errno.h>
> @@ -229,7 +230,7 @@ add_group (long int *start, long int *size, gid_t **groupsp, long int limit,
> else
> newsize = MIN (limit, 2 * *size);
>
> - newgroups = realloc (groups, newsize * sizeof (*groups));
> + newgroups = nrealloc (groups, newsize, sizeof (*groups));
> if (newgroups == NULL)
> return;
> *groupsp = groups = newgroups;
> @@ -281,7 +282,7 @@ getgrent_next_nss (ent_t *ent, char *buffer, size_t buflen, const char *user,
> {
> long int mystart = 0;
> long int mysize = limit <= 0 ? *size : limit;
> - gid_t *mygroups = malloc (mysize * sizeof (gid_t));
> + gid_t *mygroups = NMALLOC (mysize, gid_t);
>
> if (mygroups == NULL)
> return NSS_STATUS_TRYAGAIN;
> diff --git a/nis/nss_nis/nis-initgroups.c b/nis/nss_nis/nis-initgroups.c
> index 87ceca2..df92101 100644
> --- a/nis/nss_nis/nis-initgroups.c
> +++ b/nis/nss_nis/nis-initgroups.c
> @@ -16,6 +16,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <alloca.h>
> #include <ctype.h>
> #include <errno.h>
> @@ -207,7 +208,7 @@ initgroups_netid (uid_t uid, gid_t group, long int *start, long int *size,
> else
> newsize = MIN (limit, 2 * *size);
>
> - gid_t *newgroups = realloc (groups, newsize * sizeof (*groups));
> + gid_t *newgroups = nrealloc (groups, newsize, sizeof (*groups));
> if (newgroups == NULL)
> goto errout;
> *groupsp = groups = newgroups;
> @@ -295,7 +296,7 @@ _nss_nis_initgroups_dyn (const char *user, gid_t group, long int *start,
> else
> newsize = MIN (limit, 2 * *size);
>
> - newgroups = realloc (groups, newsize * sizeof (*groups));
> + newgroups = nrealloc (groups, newsize, sizeof (*groups));
> if (newgroups == NULL)
> goto done;
> *groupsp = groups = newgroups;
> diff --git a/nis/nss_nisplus/nisplus-initgroups.c b/nis/nss_nisplus/nisplus-initgroups.c
> index b54c53d..e7f9f77 100644
> --- a/nis/nss_nisplus/nisplus-initgroups.c
> +++ b/nis/nss_nisplus/nisplus-initgroups.c
> @@ -15,6 +15,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <atomic.h>
> #include <nss.h>
> #include <grp.h>
> @@ -132,7 +133,7 @@ _nss_nisplus_initgroups_dyn (const char *user, gid_t group, long int *start,
> else
> newsize = MIN (limit, 2 * *size);
>
> - gid_t *newgroups = realloc (groups, newsize * sizeof (*groups));
> + gid_t *newgroups = nrealloc (groups, newsize, sizeof (*groups));
> if (newgroups == NULL)
> goto errout;
> *groupsp = groups = newgroups;
> diff --git a/nptl/tst-cancel20.c b/nptl/tst-cancel20.c
> index e34bd11..a0a7aa5 100644
> --- a/nptl/tst-cancel20.c
> +++ b/nptl/tst-cancel20.c
> @@ -16,6 +16,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <errno.h>
> #include <pthread.h>
> #include <signal.h>
> @@ -178,7 +179,7 @@ static int
> do_test (void)
> {
> stack_t ss;
> - ss.ss_sp = malloc (2 * SIGSTKSZ);
> + ss.ss_sp = nmalloc (2, SIGSTKSZ);
> if (ss.ss_sp == NULL)
> {
> puts ("failed to allocate alternate stack");
> diff --git a/nptl/tst-cancel21.c b/nptl/tst-cancel21.c
> index 057a446..4df74c8 100644
> --- a/nptl/tst-cancel21.c
> +++ b/nptl/tst-cancel21.c
> @@ -16,6 +16,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <errno.h>
> #include <pthread.h>
> #include <signal.h>
> @@ -214,7 +215,7 @@ static int
> do_test (void)
> {
> stack_t ss;
> - ss.ss_sp = malloc (2 * SIGSTKSZ);
> + ss.ss_sp = nmalloc (2, SIGSTKSZ);
> if (ss.ss_sp == NULL)
> {
> puts ("failed to allocate alternate stack");
> diff --git a/nptl/tst-signal6.c b/nptl/tst-signal6.c
> index 2830bdf..5cea2b3 100644
> --- a/nptl/tst-signal6.c
> +++ b/nptl/tst-signal6.c
> @@ -16,6 +16,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <pthread.h>
> #include <signal.h>
> #include <stdint.h>
> @@ -86,7 +87,7 @@ tf (void *arg)
> exit (1);
> }
>
> - void *p = malloc (2 * MINSIGSTKSZ);
> + void *p = nmalloc (2, MINSIGSTKSZ);
> if (p == NULL)
> {
> puts ("tf: malloc failed");
> diff --git a/nscd/initgrcache.c b/nscd/initgrcache.c
> index 4580884..78bcf93 100644
> --- a/nscd/initgrcache.c
> +++ b/nscd/initgrcache.c
> @@ -16,6 +16,7 @@
> You should have received a copy of the GNU General Public License
> along with this program; if not, see <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <assert.h>
> #include <errno.h>
> #include <grp.h>
> @@ -111,7 +112,7 @@ addinitgroupsX (struct database_dyn *db, int fd, request_header *req,
> /* This is temporary memory, we need not (and must not) call
> mempool_alloc. */
> // XXX This really should use alloca. need to change the backends.
> - gid_t *groups = (gid_t *) malloc (size * sizeof (gid_t));
> + gid_t *groups = NMALLOC (size, gid_t);
> if (__builtin_expect (groups == NULL, 0))
> /* No more memory. */
> goto out;
> diff --git a/nscd/nscd_getserv_r.c b/nscd/nscd_getserv_r.c
> index c9c890c..273ae19 100644
> --- a/nscd/nscd_getserv_r.c
> +++ b/nscd/nscd_getserv_r.c
> @@ -16,6 +16,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <assert.h>
> #include <errno.h>
> #include <string.h>
> @@ -160,7 +161,7 @@ nscd_getserv_r (const char *crit, size_t critlen, const char *proto,
> alloca_used);
> else
> {
> - tmp = malloc (serv_resp.s_aliases_cnt * sizeof (uint32_t));
> + tmp = NMALLOC (serv_resp.s_aliases_cnt, uint32_t);
> if (tmp == NULL)
> {
> retval = ENOMEM;
> @@ -257,8 +258,7 @@ nscd_getserv_r (const char *crit, size_t critlen, const char *proto,
> alloca_used);
> else
> {
> - aliases_len = malloc (serv_resp.s_aliases_cnt
> - * sizeof (uint32_t));
> + aliases_len = NMALLOC (serv_resp.s_aliases_cnt, uint32_t);
> if (aliases_len == NULL)
> {
> retval = ENOMEM;
> diff --git a/nscd/nscd_initgroups.c b/nscd/nscd_initgroups.c
> index 19e3d79..c8e3872 100644
> --- a/nscd/nscd_initgroups.c
> +++ b/nscd/nscd_initgroups.c
> @@ -16,6 +16,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <assert.h>
> #include <errno.h>
> #include <grp.h>
> @@ -103,8 +104,7 @@ __nscd_getgrouplist (const char *user, gid_t group, long int *size,
> though we might not end up adding it. */
> if (*size < initgr_resp.ngrps + 1)
> {
> - gid_t *newp = realloc (*groupsp,
> - (initgr_resp.ngrps + 1) * sizeof (gid_t));
> + gid_t *newp = NREALLOC (*groupsp, (initgr_resp.ngrps + 1), gid_t);
> if (newp == NULL)
> /* We cannot increase the buffer size. */
> goto out_close;
> diff --git a/posix/annexc.c b/posix/annexc.c
> index 28770dc..64185c0 100644
> --- a/posix/annexc.c
> +++ b/posix/annexc.c
> @@ -15,6 +15,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <ctype.h>
> #include <fnmatch.h>
> #include <stdio.h>
> @@ -755,7 +756,7 @@ get_null_defines (void)
> if (result_len == result_max)
> {
> result_max += 10;
> - result = realloc (result, result_max * sizeof (char **));
> + result = NREALLOC (result, result_max, char **);
> if (result == NULL)
> {
> puts ("No more memory.");
> @@ -775,7 +776,7 @@ get_null_defines (void)
> if (result_len == result_max)
> {
> result_max += 1;
> - result = realloc (result, result_max * sizeof (char **));
> + result = NREALLOC (result, result_max, char **);
> if (result == NULL)
> {
> puts ("No more memory.");
> diff --git a/posix/fnmatch.c b/posix/fnmatch.c
> index 0f26a2e..b611ded 100644
> --- a/posix/fnmatch.c
> +++ b/posix/fnmatch.c
> @@ -24,6 +24,7 @@
> # define _GNU_SOURCE 1
> #endif
>
> +#include <nmalloc.h>
> #include <assert.h>
> #include <errno.h>
> #include <fnmatch.h>
> @@ -379,7 +380,7 @@ fnmatch (pattern, string, flags)
> return -2;
> }
> wpattern_malloc = wpattern
> - = (wchar_t *) malloc ((n + 1) * sizeof (wchar_t));
> + = NMALLOC ((n + 1), wchar_t);
> assert (mbsinit (&ps));
> if (wpattern == NULL)
> return -2;
> @@ -430,7 +431,7 @@ fnmatch (pattern, string, flags)
> }
>
> wstring_malloc = wstring
> - = (wchar_t *) malloc ((n + 1) * sizeof (wchar_t));
> + = NMALLOC ((n + 1), wchar_t);
> if (wstring == NULL)
> {
> free (wpattern_malloc);
> diff --git a/posix/regex_internal.h b/posix/regex_internal.h
> index 3c94fbe..9f87eaa 100644
> --- a/posix/regex_internal.h
> +++ b/posix/regex_internal.h
> @@ -429,8 +429,8 @@ static unsigned int re_string_context_at (const re_string_t *input, int idx,
> # endif
> #endif
>
> -#define re_malloc(t,n) ((t *) malloc ((n) * sizeof (t)))
> -#define re_realloc(p,t,n) ((t *) realloc (p, (n) * sizeof (t)))
> +#define re_malloc(t,n) NMALLOC (n, t)
> +#define re_realloc(p,t,n) NREALLOC (p, t, n)
> #define re_free(p) free (p)
>
> struct bin_tree_t
> diff --git a/posix/regexec.c b/posix/regexec.c
> index f85c5e8..ee2b660 100644
> --- a/posix/regexec.c
> +++ b/posix/regexec.c
> @@ -17,6 +17,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <stdint.h>
>
> static reg_errcode_t match_ctx_init (re_match_context_t *cache, int eflags,
> @@ -3400,8 +3401,7 @@ build_trtable (const re_dfa_t *dfa, re_dfastate_t *state)
> alloca (ndests * 3 * sizeof (re_dfastate_t *));
> else
> {
> - dest_states = (re_dfastate_t **)
> - malloc (ndests * 3 * sizeof (re_dfastate_t *));
> + dest_states = NMALLOC (ndests, 3 * re_dfastate_t *);
> if (BE (dest_states == NULL, 0))
> {
> out_free:
> diff --git a/posix/spawn_faction_init.c b/posix/spawn_faction_init.c
> index ced29a8..f1d1ad9 100644
> --- a/posix/spawn_faction_init.c
> +++ b/posix/spawn_faction_init.c
> @@ -15,6 +15,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <errno.h>
> #include <spawn.h>
> #include <stdlib.h>
> @@ -29,8 +30,8 @@ int
> __posix_spawn_file_actions_realloc (posix_spawn_file_actions_t *file_actions)
> {
> int newalloc = file_actions->__allocated + 8;
> - void *newmem = realloc (file_actions->__actions,
> - newalloc * sizeof (struct __spawn_action));
> + void *newmem = NREALLOC (file_actions->__actions, newalloc,
> + struct __spawn_action);
>
> if (newmem == NULL)
> /* Not enough memory. */
> diff --git a/posix/tst-mmap.c b/posix/tst-mmap.c
> index c03acf5..1523756 100644
> --- a/posix/tst-mmap.c
> +++ b/posix/tst-mmap.c
> @@ -1,3 +1,4 @@
> +#include <nmalloc.h>
> #include <assert.h>
> #include <errno.h>
> #include <stdio.h>
> @@ -93,7 +94,7 @@ main (void)
> }
>
> /* Get a valid address. */
> - mem = malloc (2 * ps);
> + mem = nmalloc (2, ps);
> if (mem != NULL)
> {
> /* Now we map at an address which is not mod pagesize. */
> diff --git a/posix/wordexp.c b/posix/wordexp.c
> index 96ce8a4..1676921 100644
> --- a/posix/wordexp.c
> +++ b/posix/wordexp.c
> @@ -17,6 +17,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <alloca.h>
> #include <ctype.h>
> #include <errno.h>
> @@ -179,7 +180,7 @@ w_addword (wordexp_t *pwordexp, char *word)
> }
>
> num_p = 2 + pwordexp->we_wordc + pwordexp->we_offs;
> - new_wordv = realloc (pwordexp->we_wordv, sizeof (char *) * num_p);
> + new_wordv = NREALLOC (pwordexp->we_wordv, num_p, char *);
> if (new_wordv != NULL)
> {
> pwordexp->we_wordv = new_wordv;
> diff --git a/resolv/gai_misc.c b/resolv/gai_misc.c
> index 6b73aac..a85ca20 100644
> --- a/resolv/gai_misc.c
> +++ b/resolv/gai_misc.c
> @@ -16,6 +16,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <assert.h>
> #include <errno.h>
> #include <pthread.h>
> @@ -116,8 +117,7 @@ get_elem (void)
> size_t new_max_size = pool_max_size + ROWS_STEP;
> struct requestlist **new_tab;
>
> - new_tab = (struct requestlist **)
> - realloc (pool, new_max_size * sizeof (struct requestlist *));
> + new_tab = NREALLOC (pool, new_max_size, struct requestlist *);
>
> if (new_tab == NULL)
> return NULL;
> diff --git a/stdlib/isomac.c b/stdlib/isomac.c
> index 621b515..92120a4 100644
> --- a/stdlib/isomac.c
> +++ b/stdlib/isomac.c
> @@ -70,6 +70,7 @@
> # define _GNU_SOURCE 1
> #endif
>
> +#include <nmalloc.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> @@ -293,7 +294,7 @@ get_null_defines (void)
> if (result_len == result_max)
> {
> result_max += 10;
> - result = realloc (result, result_max * sizeof (char **));
> + result = NREALLOC (result, result_max, char **);
> if (result == NULL)
> {
> puts ("No more memory.");
> @@ -319,7 +320,7 @@ get_null_defines (void)
> if (result_len == result_max)
> {
> result_max += 1;
> - result = realloc (result, result_max * sizeof (char **));
> + result = NREALLOC (result, result_max, char **);
> if (result == NULL)
> {
> puts ("No more memory.");
> diff --git a/stdlib/tst-qsort.c b/stdlib/tst-qsort.c
> index 2b26e74..22f04af 100644
> --- a/stdlib/tst-qsort.c
> +++ b/stdlib/tst-qsort.c
> @@ -1,4 +1,5 @@
> /* Test case by Paul Eggert <eggert@twinsun.com> */
> +#include <nmalloc.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <tst-stack-align.h>
> @@ -32,7 +33,7 @@ main (int argc, char **argv)
> {
> size_t i;
> size_t array_members = argv[1] ? atoi (argv[1]) : 50;
> - array = (struct big *) malloc (array_members * sizeof *array);
> + array = (struct big *) nmalloc (array_members, sizeof *array);
> if (array == NULL)
> {
> puts ("no memory");
> diff --git a/stdlib/tst-qsort2.c b/stdlib/tst-qsort2.c
> index 75d4a17..fe0d228 100644
> --- a/stdlib/tst-qsort2.c
> +++ b/stdlib/tst-qsort2.c
> @@ -1,3 +1,4 @@
> +#include <nmalloc.h>
> #include <stdio.h>
> #include <stdlib.h>
>
> @@ -28,7 +29,7 @@ compare (const void *a1, const void *b1)
> int
> test (size_t nmemb, size_t size)
> {
> - array = malloc (nmemb * size);
> + array = nmalloc (nmemb, size);
> if (array == NULL)
> {
> printf ("%zd x %zd: no memory", nmemb, size);
> diff --git a/string/strcoll_l.c b/string/strcoll_l.c
> index 4ee101a..7b2a87d 100644
> --- a/string/strcoll_l.c
> +++ b/string/strcoll_l.c
> @@ -17,6 +17,7 @@
> <http://www.gnu.org/licenses/>. */
>
>
> +#include <nmalloc.h>
> #include <assert.h>
> #include <langinfo.h>
> #include <locale.h>
> @@ -534,7 +535,8 @@ STRCOLL (const STRING_TYPE *s1, const STRING_TYPE *s2, __locale_t l)
> }
> else if (! __libc_use_alloca ((s1len + s2len) * (sizeof (int32_t) + 1)))
> {
> - seq1.idxarr = (int32_t *) malloc ((s1len + s2len) * (sizeof (int32_t) + 1));
> + seq1.idxarr = (int32_t *) nmalloc ((s1len + s2len),
> + (sizeof (int32_t) + 1));
>
> /* If we failed to allocate memory, we leave everything as NULL so that
> we use the nocache version of traversal and comparison functions. */
> diff --git a/string/strxfrm_l.c b/string/strxfrm_l.c
> index 3812ed6..7b84984 100644
> --- a/string/strxfrm_l.c
> +++ b/string/strxfrm_l.c
> @@ -16,6 +16,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <assert.h>
> #include <langinfo.h>
> #include <locale.h>
> @@ -151,7 +152,7 @@ STRXFRM (STRING_TYPE *dest, const STRING_TYPE *src, size_t n, __locale_t l)
> very conservative here. */
> if (! __libc_use_alloca ((srclen + 1) * (sizeof (int32_t) + 1)))
> {
> - idxarr = (int32_t *) malloc ((srclen + 1) * (sizeof (int32_t) + 1));
> + idxarr = (int32_t *) nmalloc ((srclen + 1), (sizeof (int32_t) + 1));
> rulearr = (unsigned char *) &idxarr[srclen];
>
> if (idxarr == NULL)
> diff --git a/sunrpc/auth_unix.c b/sunrpc/auth_unix.c
> index 68b42d7..c6a5254 100644
> --- a/sunrpc/auth_unix.c
> +++ b/sunrpc/auth_unix.c
> @@ -37,6 +37,7 @@
> * for the credentials.
> */
>
> +#include <nmalloc.h>
> #include <errno.h>
> #include <limits.h>
> #include <stdbool.h>
> @@ -183,7 +184,7 @@ authunix_create_default (void)
> gids = (gid_t *) alloca (max_nr_groups * sizeof (gid_t));
> else
> {
> - gids = (gid_t *) malloc (max_nr_groups * sizeof (gid_t));
> + gids = NMALLOC (max_nr_groups, gid_t);
> if (gids == NULL)
> return NULL;
> }
> diff --git a/sunrpc/svc.c b/sunrpc/svc.c
> index 53e5d9f..be33077 100644
> --- a/sunrpc/svc.c
> +++ b/sunrpc/svc.c
> @@ -52,6 +52,7 @@
> * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> */
>
> +#include <nmalloc.h>
> #include <errno.h>
> #include <unistd.h>
> #include <rpc/rpc.h>
> @@ -97,7 +98,7 @@ xprt_register (SVCXPRT *xprt)
>
> if (xports == NULL)
> {
> - xports = (SVCXPRT **) malloc (_rpc_dtablesize () * sizeof (SVCXPRT *));
> + xports = NMALLOC (_rpc_dtablesize (), SVCXPRT *);
> if (xports == NULL) /* Don´t add handle */
> return;
> }
> diff --git a/sunrpc/svc_run.c b/sunrpc/svc_run.c
> index 90dfc94..71243c5 100644
> --- a/sunrpc/svc_run.c
> +++ b/sunrpc/svc_run.c
> @@ -31,6 +31,7 @@
> * Wait for input, call server program.
> */
>
> +#include <nmalloc.h>
> #include <errno.h>
> #include <unistd.h>
> #include <libintl.h>
> @@ -64,7 +65,7 @@ svc_run (void)
> if (last_max_pollfd != max_pollfd)
> {
> struct pollfd *new_pollfd
> - = realloc (my_pollfd, sizeof (struct pollfd) * max_pollfd);
> + = NREALLOC (my_pollfd, max_pollfd, struct pollfd);
>
> if (new_pollfd == NULL)
> {
> diff --git a/sysdeps/gnu/ifaddrs.c b/sysdeps/gnu/ifaddrs.c
> index 3626c30..e31493e 100644
> --- a/sysdeps/gnu/ifaddrs.c
> +++ b/sysdeps/gnu/ifaddrs.c
> @@ -16,6 +16,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <ifaddrs.h>
> #include <net/if.h>
> #include <sys/socket.h>
> @@ -66,7 +67,7 @@ getifaddrs (struct ifaddrs **ifap)
> struct ifreq *ifr;
> int i;
>
> - storage = malloc (nifs * sizeof storage[0]);
> + storage = nmalloc (nifs, sizeof storage[0]);
> if (storage == NULL)
> {
> __close (fd);
> diff --git a/sysdeps/mach/hurd/i386/init-first.c b/sysdeps/mach/hurd/i386/init-first.c
> index 8fb613b..a480bee 100644
> --- a/sysdeps/mach/hurd/i386/init-first.c
> +++ b/sysdeps/mach/hurd/i386/init-first.c
> @@ -16,6 +16,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <assert.h>
> #include <ctype.h>
> #include <hurd.h>
> @@ -268,7 +269,7 @@ init (int *data)
>
> void call_init1 (void);
>
> - array = malloc (__hurd_threadvar_max * sizeof (unsigned long int));
> + array = NMALLOC (__hurd_threadvar_max, unsigned long int);
> if (array == NULL)
> __libc_fatal ("Can't allocate single-threaded thread variables.");
>
> diff --git a/sysdeps/mach/hurd/if_index.c b/sysdeps/mach/hurd/if_index.c
> index 713f731..3cebde1 100644
> --- a/sysdeps/mach/hurd/if_index.c
> +++ b/sysdeps/mach/hurd/if_index.c
> @@ -16,6 +16,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <error.h>
> #include <net/if.h>
> #include <string.h>
> @@ -106,7 +107,7 @@ if_nameindex (void)
> nifs = len / sizeof (struct ifreq);
> }
>
> - idx = malloc ((nifs + 1) * sizeof (struct if_nameindex));
> + idx = NMALLOC ((nifs + 1), struct if_nameindex);
> if (idx == NULL)
> {
> err = ENOBUFS;
> diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
> index 8ff74b4..f0594ca 100644
> --- a/sysdeps/posix/getaddrinfo.c
> +++ b/sysdeps/posix/getaddrinfo.c
> @@ -35,6 +35,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
>
> /* This software is Copyright 1996 by Craig Metz, All Rights Reserved. */
>
> +#include <nmalloc.h>
> #include <assert.h>
> #include <ctype.h>
> #include <errno.h>
> @@ -640,8 +641,7 @@ gaih_inet (const char *name, const struct gaih_service *service,
> alloca_used);
> else
> {
> - addrmem = malloc (i
> - * sizeof (struct gaih_addrtuple));
> + addrmem = NMALLOC (i, struct gaih_addrtuple);
> if (addrmem == NULL)
> {
> result = -EAI_MEMORY;
> @@ -712,8 +712,7 @@ gaih_inet (const char *name, const struct gaih_service *service,
> alloca_used);
> else
> {
> - addrmem = malloc (air->naddrs
> - * sizeof (struct gaih_addrtuple));
> + addrmem = NMALLOC (air->naddrs, struct gaih_addrtuple);
> if (addrmem == NULL)
> {
> result = -EAI_MEMORY;
> @@ -2171,7 +2170,7 @@ gaiconf_init (void)
> {
> if (!labellist_nullbits)
> ++nlabellist;
> - new_labels = malloc (nlabellist * sizeof (*new_labels));
> + new_labels = nmalloc (nlabellist, sizeof (*new_labels));
> if (new_labels == NULL)
> goto no_file;
>
> @@ -2204,7 +2203,7 @@ gaiconf_init (void)
> {
> if (!precedencelist_nullbits)
> ++nprecedencelist;
> - new_precedence = malloc (nprecedencelist * sizeof (*new_precedence));
> + new_precedence = nmalloc (nprecedencelist, sizeof (*new_precedence));
> if (new_precedence == NULL)
> {
> if (new_labels != default_labels)
> @@ -2243,7 +2242,7 @@ gaiconf_init (void)
> {
> if (!scopelist_nullbits)
> ++nscopelist;
> - new_scopes = malloc (nscopelist * sizeof (*new_scopes));
> + new_scopes = nmalloc (nscopelist, sizeof (*new_scopes));
> if (new_scopes == NULL)
> {
> if (new_labels != default_labels)
> diff --git a/sysdeps/posix/sprofil.c b/sysdeps/posix/sprofil.c
> index 1447a4f..d8a29db 100644
> --- a/sysdeps/posix/sprofil.c
> +++ b/sysdeps/posix/sprofil.c
> @@ -16,6 +16,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <assert.h>
> #include <signal.h>
> #include <stdlib.h>
> @@ -202,7 +203,7 @@ insert (int i, unsigned long int start, unsigned long int end, struct prof *p,
> if (prof_info.num_regions == 0)
> r = malloc (sizeof (*r));
> else
> - r = realloc (prof_info.region, (prof_info.num_regions + 1) * sizeof (*r));
> + r = nrealloc (prof_info.region, (prof_info.num_regions + 1), sizeof (*r));
> if (r == NULL)
> return -1;
>
> diff --git a/sysdeps/pthread/aio_misc.c b/sysdeps/pthread/aio_misc.c
> index 79153c8..bd2615a 100644
> --- a/sysdeps/pthread/aio_misc.c
> +++ b/sysdeps/pthread/aio_misc.c
> @@ -17,6 +17,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <aio.h>
> #include <assert.h>
> #include <errno.h>
> @@ -123,8 +124,7 @@ get_elem (void)
> size_t new_max_size = pool_max_size + ROWS_STEP;
> struct requestlist **new_tab;
>
> - new_tab = (struct requestlist **)
> - realloc (pool, new_max_size * sizeof (struct requestlist *));
> + new_tab = NREALLOC (pool, new_max_size, struct requestlist *);
>
> if (new_tab == NULL)
> return NULL;
> diff --git a/sysdeps/unix/ifreq.c b/sysdeps/unix/ifreq.c
> index 2db6d0c..2ada178 100644
> --- a/sysdeps/unix/ifreq.c
> +++ b/sysdeps/unix/ifreq.c
> @@ -16,6 +16,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include "ifreq.h"
>
>
> @@ -75,5 +76,5 @@ __ifreq (struct ifreq **ifreqs, int *num_ifs, int sockfd)
> #endif
>
> *num_ifs = nifs;
> - *ifreqs = realloc (ifc.ifc_buf, nifs * sizeof (struct ifreq));
> + *ifreqs = NREALLOC (ifc.ifc_buf, nifs, struct ifreq);
> }
> diff --git a/sysdeps/unix/sysv/linux/if_index.c b/sysdeps/unix/sysv/linux/if_index.c
> index c08bc34..be28dfc 100644
> --- a/sysdeps/unix/sysv/linux/if_index.c
> +++ b/sysdeps/unix/sysv/linux/if_index.c
> @@ -15,6 +15,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include <alloca.h>
> #include <errno.h>
> #include <string.h>
> @@ -115,7 +116,7 @@ if_nameindex_netlink (void)
> }
> }
>
> - idx = malloc ((nifs + 1) * sizeof (struct if_nameindex));
> + idx = NMALLOC ((nifs + 1), struct if_nameindex);
> if (idx == NULL)
> {
> nomem:
> diff --git a/sysdeps/unix/sysv/linux/ifreq.c b/sysdeps/unix/sysv/linux/ifreq.c
> index 4a55e8f..f591e1e 100644
> --- a/sysdeps/unix/sysv/linux/ifreq.c
> +++ b/sysdeps/unix/sysv/linux/ifreq.c
> @@ -16,6 +16,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include "ifreq.h"
> #include <kernel-features.h>
>
> @@ -71,5 +72,5 @@ __ifreq (struct ifreq **ifreqs, int *num_ifs, int sockfd)
> __close (fd);
>
> *num_ifs = nifs;
> - *ifreqs = realloc (ifc.ifc_buf, nifs * sizeof (struct ifreq));
> + *ifreqs = NREALLOC (ifc.ifc_buf, nifs, struct ifreq);
> }
> diff --git a/time/alt_digit.c b/time/alt_digit.c
> index 7cd5119..c5a461e 100644
> --- a/time/alt_digit.c
> +++ b/time/alt_digit.c
> @@ -16,6 +16,7 @@
> License along with the GNU C Library; if not, see
> <http://www.gnu.org/licenses/>. */
>
> +#include <nmalloc.h>
> #include "../locale/localeinfo.h"
> #include <bits/libc-lock.h>
> #include <stdlib.h>
> @@ -54,7 +55,7 @@ _nl_init_alt_digit (struct __locale_data *current)
>
> if (ptr != NULL)
> {
> - data->alt_digits = malloc (100 * sizeof (const char *));
> + data->alt_digits = NMALLOC (100, const char *);
> if (data->alt_digits != NULL)
> for (cnt = 0; cnt < 100; ++cnt)
> {
> @@ -125,7 +126,7 @@ _nl_get_walt_digit (unsigned int number, struct __locale_data *current)
>
> if (ptr != NULL)
> {
> - data->walt_digits = malloc (100 * sizeof (const uint32_t *));
> + data->walt_digits = NMALLOC (100, const uint32_t *);
> if (data->walt_digits != NULL)
> for (cnt = 0; cnt < 100; ++cnt)
> {
> --
> 1.8.4.rc3
>
>
> echo "@@ expression e1; type t; @@
>
> - (t *) xmalloca (e1 * sizeof (t))
> + XNMALLOCA (e1, t)" > /tmp/xmalloca1.cocci
>
> echo "@@ expression e1; type t; @@
>
> - xmalloca (e1 * sizeof (t))
> + XNMALLOCA (e1, t)" > /tmp/xmalloca2.cocci
>
> echo "@@ expression e1, e2; @@
>
> - xmalloca (e1 * e2)
> + xnmalloca (e1, e2)" > /tmp/xmalloca3.cocci
>
> SPATCHES='/tmp/xmalloca1.cocci /tmp/xmalloca2.cocci /tmp/xmalloca3.cocci'
>
> for FILE in `git grep --name-only 'malloca (' | grep 'c$' | grep -v test | grep -v bug`; do
> echo $FILE
> for SPATCH in $SPATCHES; do
> timeout 10s spatch $SPATCH -in_place $FILE 2> /dev/null
> done
> done
>
>
> echo "@@ expression e1; type t; @@
>
> - (t *) malloc (e1 * sizeof (t))
> + NMALLOC (e1, t)" > /tmp/malloc1.cocci
>
> echo "@@ expression e1; type t; @@
>
> - malloc (e1 * sizeof (t))
> + NMALLOC (e1, t)" > /tmp/malloc2.cocci
>
> echo "@@ expression e1, e2; @@
>
> - malloc (e1 * e2)
> + nmalloc (e1, e2)" > /tmp/malloc3.cocci
>
> SPATCHES='/tmp/malloc1.cocci /tmp/malloc2.cocci /tmp/malloc3.cocci'
>
> for FILE in `git grep --name-only 'malloc (.*\*' | grep 'c$' | grep -v test | grep -v bug`; do
> echo $FILE
> for SPATCH in $SPATCHES; do
> timeout 20s spatch $SPATCH -in_place $FILE 2> /dev/null
> done
> done
>
>
>
> echo "@@ expression e, e1; type t; @@
>
> - (t *) realloc (e, e1 * sizeof (t))
> + NREALLOC (e, e1, t)" > /tmp/realloc1.cocci
>
> echo "@@ expression e, e1; type t; @@
>
> - realloc (e, e1 * sizeof (t))
> + NREALLOC (e, e1, t)" > /tmp/realloc2.cocci
>
> echo "@@ expression e, e1, e2; @@
>
> - realloc (e, e1 * e2)
> + nrealloc (e, e1, e2)" > /tmp/ralloc3.cocci
>
> SPATCHES='/tmp/realloc1.cocci /tmp/realloc2.cocci /tmp/realloc3.cocci'
>
> for FILE in `git grep --name-only 'realloc (.*\*' | grep 'c$' | grep -v test | grep -v bug`; do
> echo $FILE
> for SPATCH in $SPATCHES; do
> timeout 10s spatch $SPATCH -in_place $FILE 2> /dev/null
> done
> done
>
> git diff | sed -e "s/^+\(.*[a-zA-Z0-9_]\)(/+\1 (/" > diff
> git checkout -f
> git apply diff
--
You need to install an RTFM interface.
More information about the Libc-alpha
mailing list