Source-Changes-HG archive

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

[src/trunk]: src/lib/libc/gen use reallocarr (Ingo Schwarze)



details:   https://anonhg.NetBSD.org/src/rev/869f6ef10dff
branches:  trunk
changeset: 338389:869f6ef10dff
user:      christos <christos%NetBSD.org@localhost>
date:      Thu May 21 01:29:13 2015 +0000

description:
use reallocarr (Ingo Schwarze)

diffstat:

 lib/libc/gen/stringlist.c |  18 ++++++++++--------
 1 files changed, 10 insertions(+), 8 deletions(-)

diffs (53 lines):

diff -r cede219d09c8 -r 869f6ef10dff lib/libc/gen/stringlist.c
--- a/lib/libc/gen/stringlist.c Thu May 21 01:09:00 2015 +0000
+++ b/lib/libc/gen/stringlist.c Thu May 21 01:29:13 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: stringlist.c,v 1.13 2008/04/28 20:22:59 martin Exp $   */
+/*     $NetBSD: stringlist.c,v 1.14 2015/05/21 01:29:13 christos Exp $ */
 
 /*-
  * Copyright (c) 1994, 1999 The NetBSD Foundation, Inc.
@@ -31,13 +31,14 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: stringlist.c,v 1.13 2008/04/28 20:22:59 martin Exp $");
+__RCSID("$NetBSD: stringlist.c,v 1.14 2015/05/21 01:29:13 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
 
 #include <assert.h>
 #include <err.h>
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -67,8 +68,9 @@
 
        sl->sl_cur = 0;
        sl->sl_max = _SL_CHUNKSIZE;
-       sl->sl_str = malloc(sl->sl_max * sizeof(char *));
-       if (sl->sl_str == NULL) {
+       sl->sl_str = NULL;
+       errno = reallocarr(&sl->sl_str, sl->sl_max, sizeof(char *));
+       if (errno) {
                free(sl);
                sl = NULL;
        }
@@ -86,11 +88,11 @@
        _DIAGASSERT(sl != NULL);
 
        if (sl->sl_cur == sl->sl_max - 1) {
-               char    **new;
+               char    **new = sl->sl_str;
 
-               new = realloc(sl->sl_str,
-                   (sl->sl_max + _SL_CHUNKSIZE) * sizeof(char *));
-               if (new == NULL)
+               errno = reallocarr(&new, (sl->sl_max + _SL_CHUNKSIZE),
+                   sizeof(char *));
+               if (errno)
                        return -1;
                sl->sl_max += _SL_CHUNKSIZE;
                sl->sl_str = new;



Home | Main Index | Thread Index | Old Index