Module Name: src Committed By: nia Date: Sat Oct 30 10:34:19 UTC 2021
Modified Files: src/lib/libpuffs: framebuf.c puffs.c Log Message: puffs(3): Replace realloc(x * y) with reallocarr To generate a diff of this commit: cvs rdiff -u -r1.35 -r1.36 src/lib/libpuffs/framebuf.c cvs rdiff -u -r1.124 -r1.125 src/lib/libpuffs/puffs.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libpuffs/framebuf.c diff -u src/lib/libpuffs/framebuf.c:1.35 src/lib/libpuffs/framebuf.c:1.36 --- src/lib/libpuffs/framebuf.c:1.35 Wed Jun 14 16:39:41 2017 +++ src/lib/libpuffs/framebuf.c Sat Oct 30 10:34:18 2021 @@ -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 @@ puffs__framev_addfd_ctrl(struct puffs_us 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) Index: src/lib/libpuffs/puffs.c diff -u src/lib/libpuffs/puffs.c:1.124 src/lib/libpuffs/puffs.c:1.125 --- src/lib/libpuffs/puffs.c:1.124 Sat Jun 30 16:05:44 2018 +++ src/lib/libpuffs/puffs.c Sat Oct 30 10:34:18 2021 @@ -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 @@ puffs_mainloop(struct puffs_usermount *p 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);