projects
/
gnulib.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Mention that the 'free' module, LIA-1.
[gnulib.git]
/
lib
/
xmalloc.c
diff --git
a/lib/xmalloc.c
b/lib/xmalloc.c
index
caa5ed8
..
181006b
100644
(file)
--- a/
lib/xmalloc.c
+++ b/
lib/xmalloc.c
@@
-23,7
+23,6
@@
#include "xalloc.h"
#include "xalloc.h"
-#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
#include <string.h>
@@
-49,15
+48,6
@@
/* If non NULL, call this function when memory is exhausted. */
void (*xalloc_fail_func) (void) = 0;
/* If non NULL, call this function when memory is exhausted. */
void (*xalloc_fail_func) (void) = 0;
-/* Return true if array of N objects, each of size S, cannot exist due
- to arithmetic overflow. S must be nonzero. */
-
-static inline bool
-array_size_overflow (size_t n, size_t s)
-{
- return SIZE_MAX / s < n;
-}
-
/* If XALLOC_FAIL_FUNC is NULL, or does return, display this message
before exiting when memory is exhausted. Goes through gettext. */
char const xalloc_msg_memory_exhausted[] = N_("memory exhausted");
/* If XALLOC_FAIL_FUNC is NULL, or does return, display this message
before exiting when memory is exhausted. Goes through gettext. */
char const xalloc_msg_memory_exhausted[] = N_("memory exhausted");
@@
-81,7
+71,7
@@
static inline void *
xnmalloc_inline (size_t n, size_t s)
{
void *p;
xnmalloc_inline (size_t n, size_t s)
{
void *p;
- if (
array_size_overflow
(n, s) || ! (p = malloc (n * s)))
+ if (
xalloc_oversized
(n, s) || ! (p = malloc (n * s)))
xalloc_die ();
return p;
}
xalloc_die ();
return p;
}
@@
-106,7
+96,7
@@
xmalloc (size_t n)
static inline void *
xnrealloc_inline (void *p, size_t n, size_t s)
{
static inline void *
xnrealloc_inline (void *p, size_t n, size_t s)
{
- if (
array_size_overflow
(n, s) || ! (p = realloc (p, n * s)))
+ if (
xalloc_oversized
(n, s) || ! (p = realloc (p, n * s)))
xalloc_die ();
return p;
}
xalloc_die ();
return p;
}
@@
-146,8
+136,8
@@
xrealloc (void *p, size_t n)
Here is an example of use:
int *p = NULL;
Here is an example of use:
int *p = NULL;
- size used = 0;
- size allocated = 0;
+ size
_t
used = 0;
+ size
_t
allocated = 0;
void
append_int (int value)
void
append_int (int value)
@@
-165,9
+155,9
@@
xrealloc (void *p, size_t n)
example:
int *p = NULL;
example:
int *p = NULL;
- size used = 0;
- size allocated = 0;
- size allocated1 = 1000;
+ size
_t
used = 0;
+ size
_t
allocated = 0;
+ size
_t
allocated1 = 1000;
void
append_int (int value)
void
append_int (int value)
@@
-249,7
+239,7
@@
xcalloc (size_t n, size_t s)
void *p;
/* Test for overflow, since some calloc implementations don't have
proper overflow checks. */
void *p;
/* Test for overflow, since some calloc implementations don't have
proper overflow checks. */
- if (
array_size_overflow
(n, s) || ! (p = calloc (n, s)))
+ if (
xalloc_oversized
(n, s) || ! (p = calloc (n, s)))
xalloc_die ();
return p;
}
xalloc_die ();
return p;
}