diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2016-12-15 09:59:21 -0800 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2016-12-15 10:19:48 -0800 |
commit | f8c6b7a2d1a28eca869008e56521ed5834d3bec1 (patch) | |
tree | 802ef0fdfdaa4de4da839683e5ce1cda96d84d60 /lib/xmalloc.c | |
parent | ca495b0f87b2626156c8e51555fbd58c9129d3cc (diff) | |
download | gnulib-f8c6b7a2d1a28eca869008e56521ed5834d3bec1.tar.gz |
xalloc: do not exceed PTRDIFF_MAX
* lib/xmalloc.c (xcalloc) [HAVE_GNU_CALLOC]: Do not omit
xalloc_oversized check, since objects larger than PTRDIFF_MAX
bytes have pointer-subtraction problems.
Diffstat (limited to 'lib/xmalloc.c')
-rw-r--r-- | lib/xmalloc.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/xmalloc.c b/lib/xmalloc.c index 429b50d994..7d9c077729 100644 --- a/lib/xmalloc.c +++ b/lib/xmalloc.c @@ -93,11 +93,11 @@ void * xcalloc (size_t n, size_t s) { void *p; - /* Test for overflow, since some calloc implementations don't have - proper overflow checks. But omit overflow and size-zero tests if - HAVE_GNU_CALLOC, since GNU calloc catches overflow and never - returns NULL if successful. */ - if ((! HAVE_GNU_CALLOC && xalloc_oversized (n, s)) + /* Test for overflow, since objects with size greater than + PTRDIFF_MAX cause pointer subtraction to go awry. Omit size-zero + tests if HAVE_GNU_CALLOC, since GNU calloc never returns NULL if + successful. */ + if (xalloc_oversized (n, s) || (! (p = calloc (n, s)) && (HAVE_GNU_CALLOC || n != 0))) xalloc_die (); return p; |