From: deraadt Date: Sun, 13 Jul 2014 17:34:25 +0000 (+0000) Subject: use mallocarray where arguments are multiplied; ok tedu X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=5f2418a7026722f36014aa9f68ea8cd60325f158;p=openbsd use mallocarray where arguments are multiplied; ok tedu --- diff --git a/sys/scsi/ch.c b/sys/scsi/ch.c index d00f1d0515c..818a0d0cbef 100644 --- a/sys/scsi/ch.c +++ b/sys/scsi/ch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ch.c,v 1.47 2014/07/12 18:50:25 tedu Exp $ */ +/* $OpenBSD: ch.c,v 1.48 2014/07/13 17:34:25 deraadt Exp $ */ /* $NetBSD: ch.c,v 1.26 1997/02/21 22:06:52 thorpej Exp $ */ /* @@ -596,9 +596,10 @@ ch_usergetelemstatus(struct ch_softc *sc, error = EINVAL; goto done; } - udsize = avail * sizeof(struct changer_element_status); - user_data = malloc(udsize, M_DEVBUF, M_WAITOK | M_ZERO); + user_data = mallocarray(avail, sizeof(struct changer_element_status), + M_DEVBUF, M_WAITOK | M_ZERO); + udsize = avail * sizeof(struct changer_element_status); desc = (caddr_t)(pg_hdr + 1); for (i = 0; i < avail; ++i) { diff --git a/sys/scsi/safte.c b/sys/scsi/safte.c index 5ac48e7fc61..ece1499d540 100644 --- a/sys/scsi/safte.c +++ b/sys/scsi/safte.c @@ -1,4 +1,4 @@ -/* $OpenBSD: safte.c,v 1.49 2014/07/12 18:50:25 tedu Exp $ */ +/* $OpenBSD: safte.c,v 1.50 2014/07/13 17:34:25 deraadt Exp $ */ /* * Copyright (c) 2005 David Gwynne @@ -321,7 +321,7 @@ safte_read_config(struct safte_softc *sc) sc->sc_nsensors = config->nfans + config->npwrsup + config->ntemps + (config->doorlock ? 1 : 0) + (config->alarm ? 1 : 0); - sc->sc_sensors = malloc(sc->sc_nsensors * sizeof(struct safte_sensor), + sc->sc_sensors = mallocarray(sc->sc_nsensors, sizeof(struct safte_sensor), M_DEVBUF, M_NOWAIT | M_ZERO); if (sc->sc_sensors == NULL) { dma_free(sc->sc_encbuf, sc->sc_encbuflen);