Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/indent indent: clean up memory allocation
details: https://anonhg.NetBSD.org/src/rev/faa63368a56b
branches: trunk
changeset: 375329:faa63368a56b
user: rillig <rillig%NetBSD.org@localhost>
date: Mon May 15 08:02:01 2023 +0000
description:
indent: clean up memory allocation
No functional change.
diffstat:
usr.bin/indent/indent.c | 20 ++++----------------
usr.bin/indent/indent.h | 5 ++---
usr.bin/indent/lexi.c | 10 +++++-----
3 files changed, 11 insertions(+), 24 deletions(-)
diffs (106 lines):
diff -r 3fa6a8601ddb -r faa63368a56b usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c Mon May 15 08:01:22 2023 +0000
+++ b/usr.bin/indent/indent.c Mon May 15 08:02:01 2023 +0000
@@ -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 -r 3fa6a8601ddb -r faa63368a56b usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h Mon May 15 08:01:22 2023 +0000
+++ b/usr.bin/indent/indent.h Mon May 15 08:02:01 2023 +0000
@@ -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 -r 3fa6a8601ddb -r faa63368a56b usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c Mon May 15 08:01:22 2023 +0000
+++ b/usr.bin/indent/lexi.c Mon May 15 08:02:01 2023 +0000
@@ -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));
}
Home |
Main Index |
Thread Index |
Old Index