X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=lib%2Fxmalloc.c;h=9a30d67b9fa89f52325fb3af863453b11496d056;hb=ecea6a7078983379e5b4d8961337cc55298aa8b1;hp=57e34b7cdb0d980755a2b9f6a3b395a0f57c2422;hpb=d738e90e8360e101b94fca8c79147f59565f62d8;p=debian%2Fgzip diff --git a/lib/xmalloc.c b/lib/xmalloc.c index 57e34b7..9a30d67 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-2013 Free Software Foundation, Inc. + Copyright (C) 1990-2000, 2002-2006, 2008-2018 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 @@ -13,7 +13,7 @@ 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 . */ + along with this program. If not, see . */ #include @@ -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;