From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10188 invoked by alias); 7 Aug 2002 10:21:53 -0000 Mailing-List: contact libc-hacker-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sources.redhat.com Received: (qmail 10172 invoked from network); 7 Aug 2002 10:21:52 -0000 Received: from unknown (HELO sunsite.mff.cuni.cz) (195.113.19.66) by sources.redhat.com with SMTP; 7 Aug 2002 10:21:52 -0000 Received: (from jakub@localhost) by sunsite.mff.cuni.cz (8.11.6/8.11.6) id g77ALmm25746; Wed, 7 Aug 2002 12:21:48 +0200 Date: Wed, 07 Aug 2002 03:21:00 -0000 From: Jakub Jelinek To: Ulrich Drepper Cc: Glibc hackers Subject: [PATCH] One more calloc fix Message-ID: <20020807122148.U20867@sunsite.ms.mff.cuni.cz> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5.1i X-SW-Source: 2002-08/txt/msg00093.txt.bz2 Hi! calloc (131072, 0) ought to work like malloc (0), but it will crash on 32-bit arches. The check is in the unlikely executed chunk of code, so it shouldn't slow things down. 2002-08-07 Jakub Jelinek * malloc/malloc.c (public_cALLOc): Check elem_size != 0 before division. --- libc/malloc/malloc.c.jj 2002-08-05 08:44:17.000000000 +0200 +++ libc/malloc/malloc.c 2002-08-07 12:37:58.000000000 +0200 @@ -3474,7 +3474,7 @@ public_cALLOc(size_t n, size_t elem_size #define HALF_INTERNAL_SIZE_T \ (((INTERNAL_SIZE_T) 1) << (8 * sizeof (INTERNAL_SIZE_T) / 2)) if (__builtin_expect ((n | elem_size) >= HALF_INTERNAL_SIZE_T, 0)) { - if (bytes / elem_size != n) { + if (elem_size != 0 && bytes / elem_size != n) { MALLOC_FAILURE_ACTION; return 0; } Jakub