changeset 14643:b3b2f9e830e9

xalloc-oversized: new module Due to inline functions, mere inclusion of xalloc.h can result in a link dependency on xalloc_die() on some platforms. However, there are several modules that want to use just xalloc_oversized in order to short-circuit the potential to call xalloc_die. Splitting the macro into a new header and module makes this easy. * modules/xalloc-oversized: New module. * modules/xalloc (Depends-on): Add it. * lib/xalloc.h (xalloc_oversized): Move... * lib/xalloc-oversized.h: ...into new file. Signed-off-by: Eric Blake <eblake@redhat.com>
author Eric Blake <eblake@redhat.com>
date Wed, 27 Apr 2011 15:54:30 -0600
parents 1e0bf20577a1
children 157bb0cdd13a
files ChangeLog lib/xalloc-oversized.h lib/xalloc.h modules/xalloc modules/xalloc-oversized
diffstat 5 files changed, 66 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Apr 27 15:41:54 2011 -0600
+++ b/ChangeLog	Wed Apr 27 15:54:30 2011 -0600
@@ -1,5 +1,11 @@
 2011-04-28  Eric Blake  <eblake@redhat.com>
 
+	xalloc-oversized: new module
+	* modules/xalloc-oversized: New module.
+	* modules/xalloc (Depends-on): Add it.
+	* lib/xalloc.h (xalloc_oversized): Move...
+	* lib/xalloc-oversized.h: ...into new file.
+
 	utimecmp: drop dependency on xmalloc
 	* lib/utimecmp.c (utimecmp): Work even if hash table cache fails
 	due to memory pressure.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/xalloc-oversized.h	Wed Apr 27 15:54:30 2011 -0600
@@ -0,0 +1,38 @@
+/* xalloc-oversized.h -- memory allocation size checking
+
+   Copyright (C) 1990-2000, 2003-2004, 2006-2011 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
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef XALLOC_OVERSIZED_H_
+# define XALLOC_OVERSIZED_H_
+
+# include <stddef.h>
+
+/* 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
+   works correctly even when SIZE_MAX < N.
+
+   By gnulib convention, SIZE_MAX represents overflow in size
+   calculations, so the conservative dividend to use here is
+   SIZE_MAX - 1, since SIZE_MAX might represent an overflowed value.
+   However, malloc (SIZE_MAX) fails on all known hosts where
+   sizeof (ptrdiff_t) <= sizeof (size_t), so do not bother to test for
+   exactly-SIZE_MAX allocations on such hosts; this avoids a test and
+   branch when S is known to be 1.  */
+# define xalloc_oversized(n, s) \
+    ((size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) < (n))
+
+#endif /* !XALLOC_OVERSIZED_H_ */
--- a/lib/xalloc.h	Wed Apr 27 15:41:54 2011 -0600
+++ b/lib/xalloc.h	Wed Apr 27 15:54:30 2011 -0600
@@ -20,6 +20,7 @@
 
 # include <stddef.h>
 
+# include "xalloc-oversized.h"
 
 # ifdef __cplusplus
 extern "C" {
@@ -65,22 +66,6 @@
 char *xstrdup (char const *str)
       _GL_ATTRIBUTE_MALLOC;
 
-/* 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
-   works correctly even when SIZE_MAX < N.
-
-   By gnulib convention, SIZE_MAX represents overflow in size
-   calculations, so the conservative dividend to use here is
-   SIZE_MAX - 1, since SIZE_MAX might represent an overflowed value.
-   However, malloc (SIZE_MAX) fails on all known hosts where
-   sizeof (ptrdiff_t) <= sizeof (size_t), so do not bother to test for
-   exactly-SIZE_MAX allocations on such hosts; this avoids a test and
-   branch when S is known to be 1.  */
-# define xalloc_oversized(n, s) \
-    ((size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) < (n))
-
-
 /* In the following macros, T must be an elementary or structure/union or
    typedef'ed type, or a pointer to such a type.  To apply one of the
    following macros to a function pointer or array type, you need to typedef
--- a/modules/xalloc	Wed Apr 27 15:41:54 2011 -0600
+++ b/modules/xalloc	Wed Apr 27 15:54:30 2011 -0600
@@ -9,6 +9,7 @@
 Depends-on:
 inline
 xalloc-die
+xalloc-oversized
 
 configure.ac:
 gl_XALLOC
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/xalloc-oversized	Wed Apr 27 15:54:30 2011 -0600
@@ -0,0 +1,20 @@
+Description:
+Check for memory allocation overflow.  Also see xalloc.
+
+Files:
+lib/xalloc-oversized.h
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+
+Include:
+"xalloc-oversized.h"
+
+License:
+GPL
+
+Maintainer:
+all