Source-Changes-HG archive

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

[src/trunk]: src/lib/libc/stdio vfwprintf(3): use reallocarr



details:   https://anonhg.NetBSD.org/src/rev/90b218822a9b
branches:  trunk
changeset: 363422:90b218822a9b
user:      nia <nia%NetBSD.org@localhost>
date:      Sat Mar 12 08:36:52 2022 +0000

description:
vfwprintf(3): use reallocarr

diffstat:

 lib/libc/stdio/vfwprintf.c |  20 +++++++++++++-------
 1 files changed, 13 insertions(+), 7 deletions(-)

diffs (52 lines):

diff -r a2c44be1097b -r 90b218822a9b lib/libc/stdio/vfwprintf.c
--- a/lib/libc/stdio/vfwprintf.c        Sat Mar 12 08:32:02 2022 +0000
+++ b/lib/libc/stdio/vfwprintf.c        Sat Mar 12 08:36:52 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfwprintf.c,v 1.36 2017/07/11 19:36:38 perseant Exp $  */
+/*     $NetBSD: vfwprintf.c,v 1.37 2022/03/12 08:36:52 nia Exp $       */
 
 /*-
  * Copyright (c) 1990, 1993
@@ -38,7 +38,7 @@
 static char sccsid[] = "@(#)vfprintf.c 8.1 (Berkeley) 6/4/93";
 __FBSDID("$FreeBSD: src/lib/libc/stdio/vfwprintf.c,v 1.27 2007/01/09 00:28:08 imp Exp $");
 #else
-__RCSID("$NetBSD: vfwprintf.c,v 1.36 2017/07/11 19:36:38 perseant Exp $");
+__RCSID("$NetBSD: vfwprintf.c,v 1.37 2022/03/12 08:36:52 nia Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -459,9 +459,11 @@
         * converting at most `size' bytes of the input multibyte string to
         * wide characters for printing.
         */
-       convbuf = malloc((insize + 1) * sizeof(*convbuf));
-       if (convbuf == NULL)
+       convbuf = NULL;
+       if (reallocarr(&convbuf, insize + 1, sizeof(*convbuf)) != 0) {
+               errno = ENOMEM;
                return NULL;
+       }
        wcp = convbuf;
        p = mbsarg;
        mbs = initial;
@@ -1976,12 +1978,16 @@
        if (newsize < nextarg + 1)
                newsize = nextarg + 1;
        if (oldsize == STATIC_ARG_TBL_SIZE) {
-               if ((newtable = malloc(newsize * sizeof(*newtable))) == NULL)
+               newtable = NULL;
+               if (reallocarr(&newtable, newsize, sizeof(*newtable)) != 0) {
+                       errno = ENOMEM;
                        return -1;
+               }
                memcpy(newtable, oldtable, oldsize * sizeof(*newtable));
        } else {
-               newtable = realloc(oldtable, newsize * sizeof(*newtable));
-               if (newtable == NULL) {
+               newtable = oldtable;
+               if (reallocarr(&newtable, newsize, sizeof(*newtable)) != 0) {
+                       errno = ENOMEM;
                        free(oldtable);
                        return -1;
                }



Home | Main Index | Thread Index | Old Index