summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorrillig <rillig@NetBSD.org>2023-05-15 08:02:01 +0000
committerrillig <rillig@NetBSD.org>2023-05-15 08:02:01 +0000
commitbdb79d0eb219bbdedac8e412bd5e2bb50adf8d91 (patch)
tree570214c79c31548c49c3778a49ed0e450849d0da /usr.bin
parent0e7d5516aaaa5e6c78b6f4615a6452b19b776b37 (diff)
indent: clean up memory allocation
No functional change.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/indent/indent.c20
-rw-r--r--usr.bin/indent/indent.h5
-rw-r--r--usr.bin/indent/lexi.c10
3 files changed, 11 insertions, 24 deletions
diff --git a/usr.bin/indent/indent.c b/usr.bin/indent/indent.c
index 21b746a72c0..2096f9d6e49 100644
--- a/usr.bin/indent/indent.c
+++ b/usr.bin/indent/indent.c
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.269 2023/05/15 07:57:22 rillig Exp $ */
+/* $NetBSD: indent.c,v 1.270 2023/05/15 08:02:01 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.269 2023/05/15 07:57:22 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.270 2023/05/15 08:02:01 rillig Exp $");
#include <sys/param.h>
#include <err.h>
@@ -104,7 +104,7 @@ static void
buf_expand(struct buffer *buf, size_t add_size)
{
buf->cap = buf->cap + add_size + 400;
- buf->mem = xrealloc(buf->mem, buf->cap);
+ buf->mem = nonnull(realloc(buf->mem, buf->cap));
buf->st = buf->mem;
}
@@ -1125,22 +1125,10 @@ main(int argc, char **argv)
return main_loop();
}
-static void *
+void *
nonnull(void *p)
{
if (p == NULL)
err(EXIT_FAILURE, NULL);
return p;
}
-
-void *
-xrealloc(void *p, size_t new_size)
-{
- return nonnull(realloc(p, new_size));
-}
-
-char *
-xstrdup(const char *s)
-{
- return nonnull(strdup(s));
-}
diff --git a/usr.bin/indent/indent.h b/usr.bin/indent/indent.h
index 9c9d5d115a2..76fa168539c 100644
--- a/usr.bin/indent/indent.h
+++ b/usr.bin/indent/indent.h
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.h,v 1.134 2023/05/15 07:57:22 rillig Exp $ */
+/* $NetBSD: indent.h,v 1.135 2023/05/15 08:02:01 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -404,8 +404,7 @@ void process_comment(void);
void set_option(const char *, const char *);
void load_profiles(const char *);
-void *xrealloc(void *, size_t);
-char *xstrdup(const char *);
+void *nonnull(void *);
void buf_add_char(struct buffer *, char);
void buf_add_chars(struct buffer *, const char *, size_t);
diff --git a/usr.bin/indent/lexi.c b/usr.bin/indent/lexi.c
index 8fd86bc894c..e06b9e58b39 100644
--- a/usr.bin/indent/lexi.c
+++ b/usr.bin/indent/lexi.c
@@ -1,4 +1,4 @@
-/* $NetBSD: lexi.c,v 1.186 2023/05/15 07:57:22 rillig Exp $ */
+/* $NetBSD: lexi.c,v 1.187 2023/05/15 08:02:01 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: lexi.c,v 1.186 2023/05/15 07:57:22 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.187 2023/05/15 08:02:01 rillig Exp $");
#include <stdlib.h>
#include <string.h>
@@ -625,8 +625,8 @@ register_typename(const char *name)
{
if (typenames.len >= typenames.cap) {
typenames.cap = 16 + 2 * typenames.cap;
- typenames.items = xrealloc(typenames.items,
- sizeof(typenames.items[0]) * typenames.cap);
+ typenames.items = nonnull(realloc(typenames.items,
+ sizeof(typenames.items[0]) * typenames.cap));
}
int pos = bsearch_typenames(name);
@@ -636,5 +636,5 @@ register_typename(const char *name)
pos = -(pos + 1);
memmove(typenames.items + pos + 1, typenames.items + pos,
sizeof(typenames.items[0]) * (typenames.len++ - (unsigned)pos));
- typenames.items[pos] = xstrdup(name);
+ typenames.items[pos] = nonnull(strdup(name));
}