From: tedu Date: Sun, 13 Jul 2014 15:29:04 +0000 (+0000) Subject: use mallocarray where arguments are multipled. ok deraadt X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=47e7ee29c3bb7cf8aea4f2198bbeaca547bc731f;p=openbsd use mallocarray where arguments are multipled. ok deraadt --- diff --git a/sys/kern/exec_subr.c b/sys/kern/exec_subr.c index ae01762c5ba..ae3a4cc0a8a 100644 --- a/sys/kern/exec_subr.c +++ b/sys/kern/exec_subr.c @@ -1,4 +1,4 @@ -/* $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 $ */ /* @@ -91,7 +91,7 @@ vmcmdset_extend(struct exec_vmcmd_set *evsp) 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) diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index bd6c963cfe4..7450935a2ba 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -1,4 +1,4 @@ -/* $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 $ */ /* @@ -765,7 +765,7 @@ fdexpand(struct proc *p) 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]; /* @@ -784,9 +784,9 @@ fdexpand(struct proc *p) 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); @@ -939,7 +939,7 @@ fdcopy(struct process *pr) 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)) { @@ -948,9 +948,9 @@ fdcopy(struct process *pr) 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; diff --git a/sys/kern/kern_subr.c b/sys/kern/kern_subr.c index f0f216bc190..1c0c44752bb 100644 --- a/sys/kern/kern_subr.c +++ b/sys/kern/kern_subr.c @@ -1,4 +1,4 @@ -/* $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 $ */ /* @@ -166,7 +166,7 @@ hashinit(int elements, int type, int flags, u_long *hashmask) 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++) diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index 8c0310dd307..c0a9d02cc43 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -1,4 +1,4 @@ -/* $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 $ */ /*- @@ -1854,7 +1854,7 @@ sysctl_diskinit(int update, struct proc *p) 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'; diff --git a/sys/kern/subr_autoconf.c b/sys/kern/subr_autoconf.c index f0994287b46..e716a254acb 100644 --- a/sys/kern/subr_autoconf.c +++ b/sys/kern/subr_autoconf.c @@ -1,4 +1,4 @@ -/* $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 $ */ /* @@ -462,7 +462,7 @@ config_make_softc(struct device *parent, struct cfdata *cf) 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"); diff --git a/sys/kern/subr_userconf.c b/sys/kern/subr_userconf.c index 1ff26b477da..4bc7e6254f6 100644 --- a/sys/kern/subr_userconf.c +++ b/sys/kern/subr_userconf.c @@ -1,4 +1,4 @@ -/* $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 @@ -485,7 +485,7 @@ userconf_change(int devno) 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"); diff --git a/sys/kern/sys_generic.c b/sys/kern/sys_generic.c index 63d2ccb58d2..b62f44e6722 100644 --- a/sys/kern/sys_generic.c +++ b/sys/kern/sys_generic.c @@ -1,4 +1,4 @@ -/* $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 $ */ /* @@ -616,7 +616,7 @@ dopselect(struct proc *p, int nd, fd_set *in, fd_set *ou, fd_set *ex, 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]; diff --git a/sys/kern/sysv_sem.c b/sys/kern/sysv_sem.c index d36b84524b7..ca8e25a3623 100644 --- a/sys/kern/sysv_sem.c +++ b/sys/kern/sysv_sem.c @@ -1,4 +1,4 @@ -/* $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 $ */ /* @@ -66,9 +66,9 @@ seminit(void) &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); } @@ -360,7 +360,7 @@ semctl1(struct proc *p, int semid, int semnum, int cmd, union semun *arg, 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], @@ -424,7 +424,7 @@ sys_semget(struct proc *p, void *v, register_t *retval) 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); } @@ -547,7 +547,7 @@ sys_semop(struct proc *p, void *v, register_t *retval) 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, @@ -875,11 +875,11 @@ sysctl_sysvsem(int *name, u_int namelen, void *oldp, size_t *oldlenp, 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)); diff --git a/sys/kern/sysv_shm.c b/sys/kern/sysv_shm.c index c9ea3b5f3f7..39a21e6495e 100644 --- a/sys/kern/sysv_shm.c +++ b/sys/kern/sysv_shm.c @@ -1,4 +1,4 @@ -/* $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 $ */ /* @@ -592,13 +592,13 @@ sysctl_sysvshm(int *name, u_int namelen, void *oldp, size_t *oldlenp, 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)); diff --git a/sys/kern/tty.c b/sys/kern/tty.c index 41b42bab418..8a3a41189a4 100644 --- a/sys/kern/tty.c +++ b/sys/kern/tty.c @@ -1,4 +1,4 @@ -/* $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 $ */ /*- @@ -2369,7 +2369,7 @@ ttystats_init(struct itty **ttystats) 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++) { diff --git a/sys/kern/tty_pty.c b/sys/kern/tty_pty.c index cddbad83923..e28a641c5ae 100644 --- a/sys/kern/tty_pty.c +++ b/sys/kern/tty_pty.c @@ -1,4 +1,4 @@ -/* $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 $ */ /* @@ -150,7 +150,7 @@ ptyarralloc(int nelem) { 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; } diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index a3f6e59a8b5..0b9a5945ba5 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -1,4 +1,4 @@ -/* $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 $ */ /* @@ -670,7 +670,7 @@ unp_externalize(struct mbuf *rights, socklen_t controllen) 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) { @@ -961,7 +961,7 @@ unp_gc(void) * * 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); diff --git a/sys/kern/vfs_bio.c b/sys/kern/vfs_bio.c index 16c1fc136ed..19d80b31af2 100644 --- a/sys/kern/vfs_bio.c +++ b/sys/kern/vfs_bio.c @@ -1,4 +1,4 @@ -/* $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 $ */ /* @@ -441,7 +441,7 @@ bread_cluster(struct vnode *vp, daddr_t blkno, int size, struct buf **rbpp) 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;