diff options
author | JinWang An <jinwang.an@samsung.com> | 2022-12-27 12:15:01 +0900 |
---|---|---|
committer | JinWang An <jinwang.an@samsung.com> | 2022-12-27 12:15:01 +0900 |
commit | 02a08acfc3145de1707c7704c566e4401ff5a8de (patch) | |
tree | 1c41a0a5565eb993984a585a0dd8ef13735ceede /lib/xmalloc.c | |
parent | 90dfac14e6a0169336b5b7210e4a160df8b91c68 (diff) | |
download | diffutils-upstream/3.6.tar.gz diffutils-upstream/3.6.tar.bz2 diffutils-upstream/3.6.zip |
Imported Upstream version 3.6upstream/3.6
Diffstat (limited to 'lib/xmalloc.c')
-rw-r--r-- | lib/xmalloc.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/xmalloc.c b/lib/xmalloc.c index 429b50d..a4d308d 100644 --- a/lib/xmalloc.c +++ b/lib/xmalloc.c @@ -1,6 +1,6 @@ /* xmalloc.c -- malloc with out of memory checking - Copyright (C) 1990-2000, 2002-2006, 2008-2016 Free Software Foundation, Inc. + Copyright (C) 1990-2000, 2002-2006, 2008-2017 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 @@ -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; |