Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libpuffs puffs(3): Replace realloc(x * y) with reallocarr



details:   https://anonhg.NetBSD.org/src/rev/46a186b3d54c
branches:  trunk
changeset: 1024631:46a186b3d54c
user:      nia <nia%NetBSD.org@localhost>
date:      Sat Oct 30 10:34:18 2021 +0000

description:
puffs(3): Replace realloc(x * y) with reallocarr

diffstat:

 lib/libpuffs/framebuf.c |  11 +++++------
 lib/libpuffs/puffs.c    |  12 +++++++-----
 2 files changed, 12 insertions(+), 11 deletions(-)

diffs (74 lines):

diff -r c1b942c1db0f -r 46a186b3d54c lib/libpuffs/framebuf.c
--- a/lib/libpuffs/framebuf.c   Sat Oct 30 10:01:31 2021 +0000
+++ b/lib/libpuffs/framebuf.c   Sat Oct 30 10:34:18 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: framebuf.c,v 1.35 2017/06/14 16:39:41 christos Exp $   */
+/*     $NetBSD: framebuf.c,v 1.36 2021/10/30 10:34:18 nia Exp $        */
 
 /*
  * Copyright (c) 2007  Antti Kantee.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if !defined(lint)
-__RCSID("$NetBSD: framebuf.c,v 1.35 2017/06/14 16:39:41 christos Exp $");
+__RCSID("$NetBSD: framebuf.c,v 1.36 2021/10/30 10:34:18 nia Exp $");
 #endif /* !lint */
 
 #include <sys/types.h>
@@ -778,16 +778,15 @@
        struct puffs_framectrl *pfctrl)
 {
        struct puffs_fctrl_io *fio;
-       struct kevent *newevs;
        struct kevent kev[2];
        size_t nevs;
        int rv, readenable;
 
        nevs = pu->pu_nevs+2;
-       newevs = realloc(pu->pu_evs, nevs*sizeof(struct kevent));
-       if (newevs == NULL)
+       if (reallocarr(&pu->pu_evs, nevs, sizeof(struct kevent)) != 0) {
+               errno = ENOMEM;
                return -1;
-       pu->pu_evs = newevs;
+       }
 
        fio = malloc(sizeof(struct puffs_fctrl_io));
        if (fio == NULL)
diff -r c1b942c1db0f -r 46a186b3d54c lib/libpuffs/puffs.c
--- a/lib/libpuffs/puffs.c      Sat Oct 30 10:01:31 2021 +0000
+++ b/lib/libpuffs/puffs.c      Sat Oct 30 10:34:18 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: puffs.c,v 1.124 2018/06/30 16:05:44 christos Exp $     */
+/*     $NetBSD: puffs.c,v 1.125 2021/10/30 10:34:18 nia Exp $  */
 
 /*
  * Copyright (c) 2005, 2006, 2007  Antti Kantee.  All Rights Reserved.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #if !defined(lint)
-__RCSID("$NetBSD: puffs.c,v 1.124 2018/06/30 16:05:44 christos Exp $");
+__RCSID("$NetBSD: puffs.c,v 1.125 2021/10/30 10:34:18 nia Exp $");
 #endif /* !lint */
 
 #include <sys/param.h>
@@ -962,12 +962,14 @@
                goto out;
 
        nevs = pu->pu_nevs + sigcatch;
-       curev = realloc(pu->pu_evs, nevs * sizeof(struct kevent));
-       if (curev == NULL)
+       if (reallocarr(&pu->pu_evs, nevs, sizeof(struct kevent)) != 0) {
+               errno = ENOMEM;
                goto out;
-       pu->pu_evs = curev;
+       }
        pu->pu_nevs = nevs;
 
+       curev = pu->pu_evs;
+
        LIST_FOREACH(fio, &pu->pu_ios, fio_entries) {
                EV_SET(curev, fio->io_fd, EVFILT_READ, EV_ADD,
                    0, 0, (intptr_t)fio);



Home | Main Index | Thread Index | Old Index