summaryrefslogtreecommitdiff
path: root/lib/xalloc.h
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2005-06-29 16:33:17 +0000
committerJim Meyering <jim@meyering.net>2005-06-29 16:33:17 +0000
commit22326600beda94c02c3c23b78b02f8636e9ef4fa (patch)
treeab039f9312ea4b22cedd256ac88b00c39daea192 /lib/xalloc.h
parente574d209f6098e791b5ebe03dbd931be6c927432 (diff)
downloadcoreutils-22326600beda94c02c3c23b78b02f8636e9ef4fa.tar.xz
(VERIFY_EXPR): Define.
(X2REALLOC): New macro, to make using x2realloc a little safer.
Diffstat (limited to 'lib/xalloc.h')
-rw-r--r--lib/xalloc.h11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/xalloc.h b/lib/xalloc.h
index f80977e30..cd48713ba 100644
--- a/lib/xalloc.h
+++ b/lib/xalloc.h
@@ -1,7 +1,7 @@
/* xalloc.h -- malloc with out-of-memory checking
Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
- 1999, 2000, 2003, 2004 Free Software Foundation, Inc.
+ 1999, 2000, 2003, 2004, 2005 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -56,6 +56,15 @@ void *x2nrealloc (void *p, size_t *pn, size_t s);
void *xmemdup (void const *p, size_t s);
char *xstrdup (char const *str);
+# define VERIFY_EXPR(assertion) \
+ (void)((struct {char a[(assertion) ? 1 : -1]; } *) 0)
+
+/* Using x2realloc (when appropriate) usually makes your code more
+ readable than using x2nrealloc, but it also makes it so your
+ code will malfunction if sizeof (*P) ever becomes 2 or greater.
+ So use this macro instead of using x2realloc directly. */
+# define X2REALLOC(P, PN) (VERIFY_EXPR (sizeof(*P) == 1), x2realloc (P, PN))
+
/* Return 1 if an array of N objects, each of size S, cannot exist due
to size arithmetic overflow. S must be positive and N must be
nonnegative. This is a macro, not an inline function, so that it