Source-Changes-HG archive

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

[src/trunk]: src/lib/libc/gen setmode(3): use reallocarr instead of realloc(x...



details:   https://anonhg.NetBSD.org/src/rev/a2c44be1097b
branches:  trunk
changeset: 363421:a2c44be1097b
user:      nia <nia%NetBSD.org@localhost>
date:      Sat Mar 12 08:32:02 2022 +0000

description:
setmode(3): use reallocarr instead of realloc(x * y)

diffstat:

 lib/libc/gen/setmode.c |  10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)

diffs (32 lines):

diff -r 83f2cbea9562 -r a2c44be1097b lib/libc/gen/setmode.c
--- a/lib/libc/gen/setmode.c    Sat Mar 12 08:28:30 2022 +0000
+++ b/lib/libc/gen/setmode.c    Sat Mar 12 08:32:02 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: setmode.c,v 1.35 2022/03/12 08:28:30 nia Exp $ */
+/*     $NetBSD: setmode.c,v 1.36 2022/03/12 08:32:02 nia Exp $ */
 
 /*
  * Copyright (c) 1989, 1993, 1994
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)setmode.c  8.2 (Berkeley) 3/25/94";
 #else
-__RCSID("$NetBSD: setmode.c,v 1.35 2022/03/12 08:28:30 nia Exp $");
+__RCSID("$NetBSD: setmode.c,v 1.36 2022/03/12 08:32:02 nia Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -163,9 +163,11 @@
        if (set >= endset) {                                            \
                BITCMD *newset;                                         \
                setlen += SET_LEN_INCR;                                 \
-               newset = realloc(saveset, sizeof(BITCMD) * setlen);     \
-               if (newset == NULL)                                     \
+               newset = saveset;                                       \
+               if (reallocarr(&newset, setlen, sizeof(BITCMD)) != 0) { \
+                       errno = ENOMEM;                                 \
                        goto out;                                       \
+               }                                                       \
                set = newset + (set - saveset);                         \
                saveset = newset;                                       \
                endset = newset + (setlen - 2);                         \



Home | Main Index | Thread Index | Old Index