-/* $OpenBSD: exec_subr.c,v 1.36 2014/07/12 18:43:32 tedu Exp $ */
+/* $OpenBSD: exec_subr.c,v 1.37 2014/07/13 15:29:04 tedu Exp $ */
/* $NetBSD: exec_subr.c,v 1.9 1994/12/04 03:10:42 mycroft Exp $ */
/*
evsp->evs_cnt += ocnt;
/* reallocate the command set */
- nvcp = malloc(evsp->evs_cnt * sizeof(struct exec_vmcmd), M_EXEC,
+ nvcp = mallocarray(evsp->evs_cnt, sizeof(struct exec_vmcmd), M_EXEC,
M_WAITOK);
bcopy(evsp->evs_cmds, nvcp, (ocnt * sizeof(struct exec_vmcmd)));
if (evsp->evs_cmds != evsp->evs_start)
-/* $OpenBSD: kern_descrip.c,v 1.111 2014/07/12 18:43:32 tedu Exp $ */
+/* $OpenBSD: kern_descrip.c,v 1.112 2014/07/13 15:29:04 tedu Exp $ */
/* $NetBSD: kern_descrip.c,v 1.42 1996/03/30 22:24:38 christos Exp $ */
/*
else
nfiles = 2 * fdp->fd_nfiles;
- newofile = malloc(nfiles * OFILESIZE, M_FILEDESC, M_WAITOK);
+ newofile = mallocarray(nfiles, OFILESIZE, M_FILEDESC, M_WAITOK);
newofileflags = (char *) &newofile[nfiles];
/*
free(fdp->fd_ofiles, M_FILEDESC, 0);
if (NDHISLOTS(nfiles) > NDHISLOTS(fdp->fd_nfiles)) {
- newhimap = malloc(NDHISLOTS(nfiles) * sizeof(u_int),
+ newhimap = mallocarray(NDHISLOTS(nfiles), sizeof(u_int),
M_FILEDESC, M_WAITOK);
- newlomap = malloc(NDLOSLOTS(nfiles) * sizeof(u_int),
+ newlomap = mallocarray(NDLOSLOTS(nfiles), sizeof(u_int),
M_FILEDESC, M_WAITOK);
copylen = NDHISLOTS(fdp->fd_nfiles) * sizeof(u_int);
i = newfdp->fd_nfiles;
while (i >= 2 * NDEXTENT && i > newfdp->fd_lastfile * 2)
i /= 2;
- newfdp->fd_ofiles = malloc(i * OFILESIZE, M_FILEDESC, M_WAITOK);
+ newfdp->fd_ofiles = mallocarray(i, OFILESIZE, M_FILEDESC, M_WAITOK);
newfdp->fd_ofileflags = (char *) &newfdp->fd_ofiles[i];
}
if (NDHISLOTS(i) <= NDHISLOTS(NDFILE)) {
newfdp->fd_lomap =
((struct filedesc0 *) newfdp)->fd_dlomap;
} else {
- newfdp->fd_himap = malloc(NDHISLOTS(i) * sizeof(u_int),
+ newfdp->fd_himap = mallocarray(NDHISLOTS(i), sizeof(u_int),
M_FILEDESC, M_WAITOK);
- newfdp->fd_lomap = malloc(NDLOSLOTS(i) * sizeof(u_int),
+ newfdp->fd_lomap = mallocarray(NDLOSLOTS(i), sizeof(u_int),
M_FILEDESC, M_WAITOK);
}
newfdp->fd_nfiles = i;
-/* $OpenBSD: kern_subr.c,v 1.38 2014/07/12 18:43:32 tedu Exp $ */
+/* $OpenBSD: kern_subr.c,v 1.39 2014/07/13 15:29:04 tedu Exp $ */
/* $NetBSD: kern_subr.c,v 1.15 1996/04/09 17:21:56 ragge Exp $ */
/*
panic("hashinit: bad cnt");
for (hashsize = 1; hashsize < elements; hashsize <<= 1)
continue;
- hashtbl = malloc(hashsize * sizeof(*hashtbl), type, flags);
+ hashtbl = mallocarray(hashsize, sizeof(*hashtbl), type, flags);
if (hashtbl == NULL)
return NULL;
for (i = 0; i < hashsize; i++)
-/* $OpenBSD: kern_sysctl.c,v 1.256 2014/07/12 18:43:32 tedu Exp $ */
+/* $OpenBSD: kern_sysctl.c,v 1.257 2014/07/13 15:29:04 tedu Exp $ */
/* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */
/*-
free(diskstats, M_SYSCTL, 0);
diskstats = NULL;
disknames = NULL;
- diskstats = malloc(disk_count * sizeof(struct diskstats),
+ diskstats = mallocarray(disk_count, sizeof(struct diskstats),
M_SYSCTL, M_WAITOK);
disknames = malloc(tlen, M_SYSCTL, M_WAITOK);
disknames[0] = '\0';
-/* $OpenBSD: subr_autoconf.c,v 1.77 2014/07/12 18:43:32 tedu Exp $ */
+/* $OpenBSD: subr_autoconf.c,v 1.78 2014/07/13 15:29:04 tedu Exp $ */
/* $NetBSD: subr_autoconf.c,v 1.21 1996/04/04 06:06:18 cgd Exp $ */
/*
while (new <= dev->dv_unit)
new *= 2;
cd->cd_ndevs = new;
- nsp = malloc(new * sizeof(void *), M_DEVBUF, M_NOWAIT|M_ZERO);
+ nsp = mallocarray(new, sizeof(void *), M_DEVBUF, M_NOWAIT|M_ZERO);
if (nsp == NULL)
panic("config_make_softc: %sing dev array",
old != 0 ? "expand" : "creat");
-/* $OpenBSD: subr_userconf.c,v 1.40 2014/07/12 18:43:32 tedu Exp $ */
+/* $OpenBSD: subr_userconf.c,v 1.41 2014/07/13 15:29:04 tedu Exp $ */
/*
* Copyright (c) 1996-2001 Mats O Jansson <moj@stacken.kth.se>
if (share) {
for (i = 0; locnamp[ln+i] != -1 ; i++)
;
- lk = l = (int *)malloc(sizeof(int) * i,
+ lk = l = mallocarray(i, sizeof(int),
M_TEMP, M_NOWAIT);
if (lk == NULL) {
printf("out of memory.\n");
-/* $OpenBSD: sys_generic.c,v 1.90 2014/07/12 21:21:19 matthew Exp $ */
+/* $OpenBSD: sys_generic.c,v 1.91 2014/07/13 15:29:04 tedu Exp $ */
/* $NetBSD: sys_generic.c,v 1.24 1996/03/29 00:25:32 cgd Exp $ */
/*
if (ni > sizeof(bits[0])) {
caddr_t mbits;
- mbits = malloc(ni * 6, M_TEMP, M_WAITOK|M_ZERO);
+ mbits = mallocarray(6, ni, M_TEMP, M_WAITOK|M_ZERO);
pibits[0] = (fd_set *)&mbits[ni * 0];
pibits[1] = (fd_set *)&mbits[ni * 1];
pibits[2] = (fd_set *)&mbits[ni * 2];
-/* $OpenBSD: sysv_sem.c,v 1.48 2014/07/13 15:00:40 tedu Exp $ */
+/* $OpenBSD: sysv_sem.c,v 1.49 2014/07/13 15:29:04 tedu Exp $ */
/* $NetBSD: sysv_sem.c,v 1.26 1996/02/09 19:00:25 christos Exp $ */
/*
&pool_allocator_nointr);
pool_init(&semu_pool, SEMUSZ, 0, 0, 0, "semupl",
&pool_allocator_nointr);
- sema = malloc(seminfo.semmni * sizeof(struct semid_ds *),
+ sema = mallocarray(seminfo.semmni, sizeof(struct semid_ds *),
M_SEM, M_WAITOK|M_ZERO);
- semseqs = malloc(seminfo.semmni * sizeof(unsigned short),
+ semseqs = mallocarray(seminfo.semmni, sizeof(unsigned short),
M_SEM, M_WAITOK|M_ZERO);
SLIST_INIT(&semu_list);
}
case SETALL:
if ((error = ipcperm(cred, &semaptr->sem_perm, IPC_W)))
return (error);
- semval = malloc(semaptr->sem_nsems * sizeof(arg->array[0]),
+ semval = mallocarray(semaptr->sem_nsems, sizeof(arg->array[0]),
M_TEMP, M_WAITOK);
for (i = 0; i < semaptr->sem_nsems; i++) {
error = ds_copyin(&arg->array[i], &semval[i],
return (ENOSPC);
}
semaptr_new = pool_get(&sema_pool, PR_WAITOK);
- semaptr_new->sem_base = malloc(nsems * sizeof(struct sem),
+ semaptr_new->sem_base = mallocarray(nsems, sizeof(struct sem),
M_SEM, M_WAITOK|M_ZERO);
}
if (nsops <= NSOPS)
sops = sopbuf;
else
- sops = malloc(nsops * sizeof(struct sembuf), M_SEM, M_WAITOK);
+ sops = mallocarray(nsops, sizeof(struct sembuf), M_SEM, M_WAITOK);
error = copyin(SCARG(uap, sops), sops, nsops * sizeof(struct sembuf));
if (error != 0) {
DPRINTF(("error = %d from copyin(%p, %p, %u)\n", error,
return (EINVAL);
/* Expand semsegs and semseqs arrays */
- sema_new = malloc(val * sizeof(struct semid_ds *),
+ sema_new = mallocarray(val, sizeof(struct semid_ds *),
M_SEM, M_WAITOK|M_ZERO);
bcopy(sema, sema_new,
seminfo.semmni * sizeof(struct semid_ds *));
- newseqs = malloc(val * sizeof(unsigned short), M_SEM,
+ newseqs = mallocarray(val, sizeof(unsigned short), M_SEM,
M_WAITOK|M_ZERO);
bcopy(semseqs, newseqs,
seminfo.semmni * sizeof(unsigned short));
-/* $OpenBSD: sysv_shm.c,v 1.57 2014/07/12 18:43:32 tedu Exp $ */
+/* $OpenBSD: sysv_shm.c,v 1.58 2014/07/13 15:29:04 tedu Exp $ */
/* $NetBSD: sysv_shm.c,v 1.50 1998/10/21 22:24:29 tron Exp $ */
/*
return (EINVAL);
/* Expand shmsegs and shmseqs arrays */
- newsegs = malloc(val * sizeof(struct shmid_ds *),
+ newsegs = mallocarray(val, sizeof(struct shmid_ds *),
M_SHM, M_WAITOK|M_ZERO);
bcopy(shmsegs, newsegs,
shminfo.shmmni * sizeof(struct shmid_ds *));
free(shmsegs, M_SHM, 0);
shmsegs = newsegs;
- newseqs = malloc(val * sizeof(unsigned short), M_SHM,
+ newseqs = mallocarray(val, sizeof(unsigned short), M_SHM,
M_WAITOK|M_ZERO);
bcopy(shmseqs, newseqs,
shminfo.shmmni * sizeof(unsigned short));
-/* $OpenBSD: tty.c,v 1.112 2014/07/13 14:56:56 guenther Exp $ */
+/* $OpenBSD: tty.c,v 1.113 2014/07/13 15:29:04 tedu Exp $ */
/* $NetBSD: tty.c,v 1.68.4.2 1996/06/06 16:04:52 thorpej Exp $ */
/*-
struct itty *itp;
struct tty *tp;
- *ttystats = malloc(tty_count * sizeof(struct itty),
+ *ttystats = mallocarray(tty_count, sizeof(struct itty),
M_SYSCTL, M_WAITOK|M_ZERO);
for (tp = TAILQ_FIRST(&ttylist), itp = *ttystats; tp;
tp = TAILQ_NEXT(tp, tty_link), itp++) {
-/* $OpenBSD: tty_pty.c,v 1.67 2014/07/12 18:43:32 tedu Exp $ */
+/* $OpenBSD: tty_pty.c,v 1.68 2014/07/13 15:29:04 tedu Exp $ */
/* $NetBSD: tty_pty.c,v 1.33.4.1 1996/06/02 09:08:11 mrg Exp $ */
/*
{
struct pt_softc **pt;
- pt = malloc(nelem * sizeof(struct pt_softc *), M_DEVBUF,
+ pt = mallocarray(nelem, sizeof(struct pt_softc *), M_DEVBUF,
M_WAITOK|M_ZERO);
return pt;
}
-/* $OpenBSD: uipc_usrreq.c,v 1.74 2014/07/12 18:43:32 tedu Exp $ */
+/* $OpenBSD: uipc_usrreq.c,v 1.75 2014/07/13 15:29:04 tedu Exp $ */
/* $NetBSD: uipc_usrreq.c,v 1.18 1996/02/09 19:00:50 christos Exp $ */
/*
rp = (struct file **)CMSG_DATA(cm);
- fdp = malloc(nfds * sizeof(int), M_TEMP, M_WAITOK);
+ fdp = mallocarray(nfds, sizeof(int), M_TEMP, M_WAITOK);
/* Make sure the recipient should be able to see the descriptors.. */
if (p->p_fd->fd_rdir != NULL) {
*
* 91/09/19, bsy@cs.cmu.edu
*/
- extra_ref = malloc(nfiles * sizeof(struct file *), M_FILE, M_WAITOK);
+ extra_ref = mallocarray(nfiles, sizeof(struct file *), M_FILE, M_WAITOK);
for (nunref = 0, fp = LIST_FIRST(&filehead), fpp = extra_ref;
fp != NULL; fp = nextfp) {
nextfp = LIST_NEXT(fp, f_list);
-/* $OpenBSD: vfs_bio.c,v 1.158 2014/07/12 18:43:32 tedu Exp $ */
+/* $OpenBSD: vfs_bio.c,v 1.159 2014/07/13 15:29:04 tedu Exp $ */
/* $NetBSD: vfs_bio.c,v 1.44 1996/06/11 11:15:36 pk Exp $ */
/*
if (howmany > maxra)
howmany = maxra;
- xbpp = malloc((howmany + 1) * sizeof(struct buf *), M_TEMP, M_NOWAIT);
+ xbpp = mallocarray((howmany + 1), sizeof(struct buf *), M_TEMP, M_NOWAIT);
if (xbpp == NULL)
goto out;