X-Git-Url: https://git.gag.com/?p=debian%2Fgzip;a=blobdiff_plain;f=lib%2Fxmalloc.c;h=9a30d67b9fa89f52325fb3af863453b11496d056;hp=429b50d9946c7fc8d3919845066d1aa629624912;hb=a8a88eddaa90432e6ec1b8d9d5c9842bc91afd1d;hpb=20fcfc81ece044b8b0a6768ec6cf47be4e22a2e6 diff --git a/lib/xmalloc.c b/lib/xmalloc.c index 429b50d..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-2016 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;