summaryrefslogtreecommitdiff
path: root/lib/libc/stdlib
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>2022-03-12 17:31:39 +0000
committerchristos <christos@NetBSD.org>2022-03-12 17:31:39 +0000
commit03a54253ca9cf1eb97b8f417778086866a5ddc7e (patch)
tree9fa7d56feb9f3ffeaccb82028e5ac58408efca81 /lib/libc/stdlib
parent7514fbbbd886426197bc2d65a35aed350eb5efa4 (diff)
reallocarr returns errno. preserve it.
Diffstat (limited to 'lib/libc/stdlib')
-rw-r--r--lib/libc/stdlib/_env.c18
-rw-r--r--lib/libc/stdlib/hcreate.c14
-rw-r--r--lib/libc/stdlib/radixsort.c11
3 files changed, 18 insertions, 25 deletions
diff --git a/lib/libc/stdlib/_env.c b/lib/libc/stdlib/_env.c
index a5d947ad386..6608522790f 100644
--- a/lib/libc/stdlib/_env.c
+++ b/lib/libc/stdlib/_env.c
@@ -1,4 +1,4 @@
-/* $NetBSD: _env.c,v 1.12 2022/03/12 08:44:38 nia Exp $ */
+/* $NetBSD: _env.c,v 1.13 2022/03/12 17:31:39 christos Exp $ */
/*-
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: _env.c,v 1.12 2022/03/12 08:44:38 nia Exp $");
+__RCSID("$NetBSD: _env.c,v 1.13 2022/03/12 17:31:39 christos Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
@@ -297,22 +297,20 @@ __getenvslot(const char *name, size_t l_name, bool allocate)
/* Allocate a new environment array. */
if (environ == allocated_environ) {
new_environ = environ;
- if (reallocarr(&new_environ,
- new_size, sizeof(*new_environ)) != 0) {
- errno = ENOMEM;
+ errno = reallocarr(&new_environ,
+ new_size, sizeof(*new_environ));
+ if (errno)
return -1;
- }
} else {
free(allocated_environ);
allocated_environ = NULL;
allocated_environ_size = 0;
new_environ = NULL;
- if (reallocarr(&new_environ,
- new_size, sizeof(*new_environ)) != 0) {
- errno = ENOMEM;
+ errno = reallocarr(&new_environ,
+ new_size, sizeof(*new_environ));
+ if (errno)
return -1;
- }
(void)memcpy(new_environ, environ,
num_entries * sizeof(*new_environ));
}
diff --git a/lib/libc/stdlib/hcreate.c b/lib/libc/stdlib/hcreate.c
index ba32e5a6e00..be94e531bc3 100644
--- a/lib/libc/stdlib/hcreate.c
+++ b/lib/libc/stdlib/hcreate.c
@@ -1,4 +1,4 @@
-/* $NetBSD: hcreate.c,v 1.11 2022/03/12 08:26:01 nia Exp $ */
+/* $NetBSD: hcreate.c,v 1.12 2022/03/12 17:31:39 christos Exp $ */
/*
* Copyright (c) 2001 Christopher G. Demetriou
@@ -43,7 +43,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: hcreate.c,v 1.11 2022/03/12 08:26:01 nia Exp $");
+__RCSID("$NetBSD: hcreate.c,v 1.12 2022/03/12 17:31:39 christos Exp $");
#endif /* LIBC_SCCS and not lint */
#if !defined(lint)
@@ -104,7 +104,6 @@ hcreate_r(size_t nel, struct hsearch_data *head)
struct internal_head *table;
size_t idx;
unsigned int p2;
- void *p;
/* If nel is too small, make it min sized. */
if (nel < MIN_BUCKETS)
@@ -125,13 +124,10 @@ hcreate_r(size_t nel, struct hsearch_data *head)
/* Allocate the table. */
head->size = nel;
head->filled = 0;
- p = NULL;
- if (reallocarr(&p, nel, sizeof(table[0])) != 0) {
- errno = ENOMEM;
+ errno = reallocarr(&table, nel, sizeof(*table));
+ if (errno)
return 0;
- }
- head->table = p;
- table = p;
+ head->table = (void *)table;
/* Initialize it. */
for (idx = 0; idx < nel; idx++)
diff --git a/lib/libc/stdlib/radixsort.c b/lib/libc/stdlib/radixsort.c
index d9062051d47..2217687702a 100644
--- a/lib/libc/stdlib/radixsort.c
+++ b/lib/libc/stdlib/radixsort.c
@@ -1,4 +1,4 @@
-/* $NetBSD: radixsort.c,v 1.21 2021/10/29 11:03:46 nia Exp $ */
+/* $NetBSD: radixsort.c,v 1.22 2022/03/12 17:31:39 christos Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)radixsort.c 8.2 (Berkeley) 4/28/95";
#else
-__RCSID("$NetBSD: radixsort.c,v 1.21 2021/10/29 11:03:46 nia Exp $");
+__RCSID("$NetBSD: radixsort.c,v 1.22 2022/03/12 17:31:39 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -130,10 +130,9 @@ sradixsort(const u_char **a, int n, const u_char *tab, u_int endch)
simplesort(a, n, 0, tr, endch);
else {
ta = NULL;
- if (reallocarr(&ta, n, sizeof(a)) != 0) {
- errno = ENOMEM;
- return (-1);
- }
+ errno = reallocarr(&ta, n, sizeof(*ta));
+ if (errno)
+ return -1;
r_sort_b(a, ta, n, 0, tr, endch);
free(ta);
}