This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] Refactor malloc (x * sizeof (t) to XNMALLOC (x, t).
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: libc-alpha at sourceware dot org
- Date: Thu, 31 Oct 2013 17:46:14 +0100
- Subject: [PATCH] Refactor malloc (x * sizeof (t) to XNMALLOC (x, t).
- Authentication-results: sourceware.org; auth=none
Hi,
As previously suggested we can simplify malloc (x * sizeof (t)) using XNMALLOC macro.
This change is a interface issue, a overflow checking logic will be
supplied later.
This is generated by following coccinelle script
@@ expression e1; type t; @@
- malloc (e1 * sizeof (t))
+ XNMALLOC (e1, t)
with some additional script add appropriate header.
I put this into macro to libc-internal for now.
OK to commit?
ChangeLog:
* include/libc-internal.h: Add XNMALLOC macro.
* argp/argp-help.c (hol_append, make_hol):
Use XNMALLOC instead of malloc.
* elf/dl-open.c (add_to_global): Likewise.
* elf/dl-tls.c (_dl_update_slotinfo): Likewise.
* grp/initgroups.c (getgrouplist, initgroups): Likewise.
* hesiod/hesiod.c (get_txt_records): Likewise.
* hurd/hurdmsg.c (_S_msg_set_environment): Likewise.
* hurd/hurdsig.c (_hurdsig_init): Likewise.
* iconv/gconv_cache.c (__gconv_lookup_cache): Likewise.
* iconv/gconv_db.c (gen_steps): Likewise.
* libio/wgenops.c (_IO_wdefault_pbackfail, save_for_wbackup): Likewise.
* misc/getusershell.c (initshells): Likewise.
* nis/nis_findserv.c (__nis_findfastest_with_timeout): Likewise.
* nis/nis_getservlist.c (nis_getservlist): Likewise.
* nis/nis_subr.c (nis_getnames): Likewise.
* nis/nss_compat/compat-initgroups.c (getgrent_next_nss): Likewise.
* nscd/initgrcache.c (addinitgroupsX): Likewise.
* nscd/nscd_getserv_r.c (nscd_getserv_r): Likewise.
* posix/fnmatch.c (fnmatch): Likewise.
* stdio-common/xbug.c (InitBuffer): Likewise.
* sunrpc/auth_unix.c (authunix_create_default): Likewise.
* sunrpc/svc.c (xprt_register): Likewise.
* sysdeps/mach/hurd/i386/init-first.c (init): Likewise.
* sysdeps/mach/hurd/if_index.c (if_nameindex): Likewise.
* sysdeps/unix/sysv/linux/if_index.c (if_nameindex_netlink): Likewise.
* time/alt_digit.c (_nl_get_walt_digit, _nl_init_alt_digit): Likewise.
localedata/ChangeLog:
* collate-test.c (main): Use XNMALLOC instead of malloc.
* xfrm-test.c (main): Likewise.
---
argp/argp-help.c | 5 +++--
elf/dl-open.c | 7 +++----
elf/dl-tls.c | 3 ++-
grp/initgroups.c | 5 +++--
hesiod/hesiod.c | 3 ++-
hurd/hurdmsg.c | 3 ++-
hurd/hurdsig.c | 3 ++-
iconv/gconv_cache.c | 8 ++++----
iconv/gconv_db.c | 4 ++--
include/libc-internal.h | 2 ++
libio/wgenops.c | 9 ++++-----
localedata/collate-test.c | 3 ++-
localedata/xfrm-test.c | 3 ++-
misc/getusershell.c | 3 ++-
nis/nis_findserv.c | 3 ++-
nis/nis_getservlist.c | 5 +++--
nis/nis_subr.c | 3 ++-
nis/nss_compat/compat-initgroups.c | 3 ++-
nscd/initgrcache.c | 3 ++-
nscd/nscd_getserv_r.c | 6 +++---
posix/fnmatch.c | 7 +++----
stdio-common/xbug.c | 3 ++-
sunrpc/auth_unix.c | 3 ++-
sunrpc/svc.c | 3 ++-
sysdeps/mach/hurd/i386/init-first.c | 3 ++-
sysdeps/mach/hurd/if_index.c | 3 ++-
sysdeps/unix/sysv/linux/if_index.c | 3 ++-
time/alt_digit.c | 5 +++--
28 files changed, 67 insertions(+), 47 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 <libc-internal.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 = XNMALLOC (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));
+ XNMALLOC (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/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 <libc-internal.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 = XNMALLOC (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 = XNMALLOC (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..36ebac7 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 <libc-internal.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 = XNMALLOC (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 <libc-internal.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 = XNMALLOC (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 = XNMALLOC (size, gid_t);
if (__builtin_expect (groups == NULL, 0))
/* No more memory. */
return -1;
diff --git a/hesiod/hesiod.c b/hesiod/hesiod.c
index 657dabe..8b0fc39 100644
--- a/hesiod/hesiod.c
+++ b/hesiod/hesiod.c
@@ -33,6 +33,7 @@ static const char rcsid[] = "$BINDId: hesiod.c,v 1.21 2000/02/28 14:51:08 vixie
/* Imports */
+#include <libc-internal.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
@@ -400,7 +401,7 @@ get_txt_records(struct hesiod_p *ctx, int class, const char *name) {
cp += skip + QFIXEDSZ;
}
- list = malloc((ancount + 1) * sizeof(char *));
+ list = XNMALLOC (ancount + 1, char *);
if (!list)
return (NULL);
j = 0;
diff --git a/hurd/hurdmsg.c b/hurd/hurdmsg.c
index 6e350ee..2c0aa5a 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 <libc-internal.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 = XNMALLOC (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 <libc-internal.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));
+ XNMALLOC (__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/iconv/gconv_cache.c b/iconv/gconv_cache.c
index ccd2d6e..e5a2eeb 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 <libc-internal.h>
#include <dlfcn.h>
#include <errno.h>
#include <fcntl.h>
@@ -313,9 +314,8 @@ __gconv_lookup_cache (const char *toset, const char *fromset,
int idx;
*nsteps = extra->module_cnt;
- *handle = result =
- (struct __gconv_step *) malloc (extra->module_cnt
- * sizeof (struct __gconv_step));
+ *handle = result = XNMALLOC (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 = XNMALLOC (2, struct __gconv_step);
if (result == NULL)
return __GCONV_NOMEM;
diff --git a/iconv/gconv_db.c b/iconv/gconv_db.c
index b533dc0..6290ae2 100644
--- a/iconv/gconv_db.c
+++ b/iconv/gconv_db.c
@@ -17,6 +17,7 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
+#include <libc-internal.h>
#include <assert.h>
#include <limits.h>
#include <search.h>
@@ -248,8 +249,7 @@ gen_steps (struct derivation_step *best, const char *toset,
for (current = best; current->last != NULL; current = current->last)
++step_cnt;
- result = (struct __gconv_step *) malloc (sizeof (struct __gconv_step)
- * step_cnt);
+ result = XNMALLOC (step_cnt, struct __gconv_step);
if (result != NULL)
{
int failed = 0;
diff --git a/include/libc-internal.h b/include/libc-internal.h
index 78f82da..b42a6ff 100644
--- a/include/libc-internal.h
+++ b/include/libc-internal.h
@@ -70,4 +70,6 @@ extern void __init_misc (int, char **, char **);
#define PTR_ALIGN_UP(base, size) \
((__typeof__ (base)) ALIGN_UP ((uintptr_t) (base), (size)))
+#define XNMALLOC(e, tp) (tp *) malloc ((e) * sizeof (tp))
+
#endif /* _LIBC_INTERNAL */
diff --git a/libio/wgenops.c b/libio/wgenops.c
index b39b691..982d911 100644
--- a/libio/wgenops.c
+++ b/libio/wgenops.c
@@ -28,6 +28,7 @@
/* Generic or default I/O operations. */
+#include <libc-internal.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 = XNMALLOC (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 = XNMALLOC (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 = XNMALLOC (avail + needed_size, wchar_t);
if (new_buffer == NULL)
return EOF; /* FIXME */
if (least_mark < 0)
diff --git a/localedata/collate-test.c b/localedata/collate-test.c
index dfc15b0..680ed56 100644
--- a/localedata/collate-test.c
+++ b/localedata/collate-test.c
@@ -17,6 +17,7 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
+#include <libc-internal.h>
#include <ctype.h>
#include <error.h>
#include <locale.h>
@@ -50,7 +51,7 @@ main (int argc, char *argv[])
nstrings_max = 100;
nstrings = 0;
- strings = (struct lines *) malloc (nstrings_max * sizeof (struct lines));
+ strings = XNMALLOC (nstrings_max, struct lines);
if (strings == NULL)
{
perror (argv[0]);
diff --git a/localedata/xfrm-test.c b/localedata/xfrm-test.c
index 80fc1fd..95d39b5 100644
--- a/localedata/xfrm-test.c
+++ b/localedata/xfrm-test.c
@@ -17,6 +17,7 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
+#include <libc-internal.h>
#include <ctype.h>
#include <error.h>
#include <locale.h>
@@ -50,7 +51,7 @@ main (int argc, char *argv[])
nstrings_max = 100;
nstrings = 0;
- strings = (struct lines *) malloc (nstrings_max * sizeof (struct lines));
+ strings = XNMALLOC (nstrings_max, struct lines);
if (strings == NULL)
{
perror (argv[0]);
diff --git a/misc/getusershell.c b/misc/getusershell.c
index fc2c43b..20d3543 100644
--- a/misc/getusershell.c
+++ b/misc/getusershell.c
@@ -31,6 +31,7 @@
static char sccsid[] = "@(#)getusershell.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
+#include <libc-internal.h>
#include <sys/param.h>
#include <sys/file.h>
#include <sys/stat.h>
@@ -119,7 +120,7 @@ initshells (void)
flen = statb.st_size + 3;
if ((strings = malloc(flen)) == NULL)
goto init_okshells;
- shells = malloc(statb.st_size / 3 * sizeof (char *));
+ shells = XNMALLOC (statb.st_size / 3, char *);
if (shells == NULL) {
free(strings);
strings = NULL;
diff --git a/nis/nis_findserv.c b/nis/nis_findserv.c
index c5269c2..cbe8756 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 <libc-internal.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 = XNMALLOC (pings_max, struct findserv_req);
xid_seed = (u_int32_t) (time (NULL) ^ getpid ());
if (__builtin_expect (pings == NULL, 0))
diff --git a/nis/nis_getservlist.c b/nis/nis_getservlist.c
index 54840ab..aef65f3 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 <libc-internal.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));
+ XNMALLOC ((NIS_RES_OBJECT(res)->DI_data.do_servers.do_servers_len + 1),
+ nis_server *);
if (__builtin_expect (serv == NULL, 0))
{
nis_freeresult (res);
diff --git a/nis/nis_subr.c b/nis/nis_subr.c
index a03600d..ad8f778 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 <libc-internal.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 = (nis_name *) XNMALLOC (count + 1, char *);
if (__builtin_expect (getnames == NULL, 0))
return NULL;
diff --git a/nis/nss_compat/compat-initgroups.c b/nis/nss_compat/compat-initgroups.c
index cf924c4..586eb6e 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 <libc-internal.h>
#include <alloca.h>
#include <ctype.h>
#include <errno.h>
@@ -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 = XNMALLOC (mysize, gid_t);
if (mygroups == NULL)
return NSS_STATUS_TRYAGAIN;
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 <libc-internal.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 = XNMALLOC (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 <libc-internal.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 = XNMALLOC (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 = XNMALLOC (serv_resp.s_aliases_cnt, uint32_t);
if (aliases_len == NULL)
{
retval = ENOMEM;
diff --git a/posix/fnmatch.c b/posix/fnmatch.c
index 0f26a2e..8a78dfd 100644
--- a/posix/fnmatch.c
+++ b/posix/fnmatch.c
@@ -24,6 +24,7 @@
# define _GNU_SOURCE 1
#endif
+#include <libc-internal.h>
#include <assert.h>
#include <errno.h>
#include <fnmatch.h>
@@ -378,8 +379,7 @@ fnmatch (pattern, string, flags)
__set_errno (ENOMEM);
return -2;
}
- wpattern_malloc = wpattern
- = (wchar_t *) malloc ((n + 1) * sizeof (wchar_t));
+ wpattern_malloc = wpattern = XNMALLOC (n + 1, wchar_t);
assert (mbsinit (&ps));
if (wpattern == NULL)
return -2;
@@ -429,8 +429,7 @@ fnmatch (pattern, string, flags)
return -2;
}
- wstring_malloc = wstring
- = (wchar_t *) malloc ((n + 1) * sizeof (wchar_t));
+ wstring_malloc = wstring = XNMALLOC (n + 1, wchar_t);
if (wstring == NULL)
{
free (wpattern_malloc);
diff --git a/stdio-common/xbug.c b/stdio-common/xbug.c
index 64ba314..e62a2d5 100644
--- a/stdio-common/xbug.c
+++ b/stdio-common/xbug.c
@@ -1,3 +1,4 @@
+#include <libc-internal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -19,7 +20,7 @@ void InitBuffer(b)
{
b->room = INIT_BUFFER_SIZE;
b->used = 0;
- b->buff = (char *)malloc(INIT_BUFFER_SIZE*sizeof(char));
+ b->buff = XNMALLOC (INIT_BUFFER_SIZE, char);
}
void AppendToBuffer(b, str, len)
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 <libc-internal.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 = XNMALLOC (max_nr_groups, gid_t);
if (gids == NULL)
return NULL;
}
diff --git a/sunrpc/svc.c b/sunrpc/svc.c
index 53e5d9f..e59fadb 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 <libc-internal.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 = XNMALLOC (_rpc_dtablesize(), SVCXPRT *);
if (xports == NULL) /* Don´t add handle */
return;
}
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 <libc-internal.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 = XNMALLOC (__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..3069180 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 <libc-internal.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 = XNMALLOC (nifs + 1, struct if_nameindex);
if (idx == NULL)
{
err = ENOBUFS;
diff --git a/sysdeps/unix/sysv/linux/if_index.c b/sysdeps/unix/sysv/linux/if_index.c
index c08bc34..dcc6129 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 <libc-internal.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 = XNMALLOC (nifs + 1, struct if_nameindex);
if (idx == NULL)
{
nomem:
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 <libc-internal.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 = XNMALLOC (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 = XNMALLOC (100, const uint32_t *);
if (data->walt_digits != NULL)
for (cnt = 0; cnt < 100; ++cnt)
{
--
1.8.4.rc3