Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/xlint/common lint: make memory management code easie...
details: https://anonhg.NetBSD.org/src/rev/a141ed5d0fcf
branches: trunk
changeset: 1022722:a141ed5d0fcf
user: rillig <rillig%NetBSD.org@localhost>
date: Tue Aug 03 17:20:02 2021 +0000
description:
lint: make memory management code easier to read
No functional change.
diffstat:
usr.bin/xlint/common/mem.c | 36 ++++++++++++------------------------
1 files changed, 12 insertions(+), 24 deletions(-)
diffs (89 lines):
diff -r 56c733349610 -r a141ed5d0fcf usr.bin/xlint/common/mem.c
--- a/usr.bin/xlint/common/mem.c Tue Aug 03 13:40:33 2021 +0000
+++ b/usr.bin/xlint/common/mem.c Tue Aug 03 17:20:02 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mem.c,v 1.15 2021/08/01 18:13:53 rillig Exp $ */
+/* $NetBSD: mem.c,v 1.16 2021/08/03 17:20:02 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: mem.c,v 1.15 2021/08/01 18:13:53 rillig Exp $");
+__RCSID("$NetBSD: mem.c,v 1.16 2021/08/03 17:20:02 rillig Exp $");
#endif
#include <stdarg.h>
@@ -46,53 +46,41 @@
#include "lint.h"
-static void __attribute__((noreturn))
-nomem(void)
+static void *
+not_null(void *ptr)
{
- errx(1, "virtual memory exhausted");
+ if (ptr == NULL)
+ errx(1, "virtual memory exhausted");
+ return ptr;
}
void *
xmalloc(size_t s)
{
- void *p;
- if ((p = malloc(s)) == NULL)
- nomem();
- return p;
+ return not_null(malloc(s));
}
void *
xcalloc(size_t n, size_t s)
{
- void *p;
- if ((p = calloc(n, s)) == NULL)
- nomem();
- return p;
+ return not_null(calloc(n, s));
}
void *
xrealloc(void *p, size_t s)
{
- void *n;
- if ((n = realloc(p, s)) == NULL) {
- free(p);
- nomem();
- }
- return n;
+ return not_null(realloc(p, s));
}
char *
xstrdup(const char *s)
{
- char *s2;
- if ((s2 = strdup(s)) == NULL)
- nomem();
- return s2;
+ return not_null(strdup(s));
}
char *
@@ -106,6 +94,6 @@
e = vasprintf(&str, fmt, ap);
va_end(ap);
if (e < 0)
- nomem();
+ not_null(NULL);
return str;
}
Home |
Main Index |
Thread Index |
Old Index