Module Name: src
Committed By: christos
Date: Thu May 21 01:29:13 UTC 2015
Modified Files:
src/lib/libc/gen: stringlist.c
Log Message:
use reallocarr (Ingo Schwarze)
To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/lib/libc/gen/stringlist.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/libc/gen/stringlist.c
diff -u src/lib/libc/gen/stringlist.c:1.13 src/lib/libc/gen/stringlist.c:1.14
--- src/lib/libc/gen/stringlist.c:1.13 Mon Apr 28 16:22:59 2008
+++ src/lib/libc/gen/stringlist.c Wed May 20 21:29:13 2015
@@ -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_init(void)
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 @@ sl_add(StringList *sl, char *name)
_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;