From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18710 invoked by alias); 29 Jun 2011 07:05:11 -0000 Received: (qmail 18693 invoked by uid 22791); 29 Jun 2011 07:05:09 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from mail-pz0-f47.google.com (HELO mail-pz0-f47.google.com) (209.85.210.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 29 Jun 2011 07:04:56 +0000 Received: by pzk36 with SMTP id 36so699428pzk.20 for ; Wed, 29 Jun 2011 00:04:55 -0700 (PDT) MIME-Version: 1.0 Received: by 10.68.0.227 with SMTP id 3mr653097pbh.284.1309331095133; Wed, 29 Jun 2011 00:04:55 -0700 (PDT) Received: by 10.68.44.67 with HTTP; Wed, 29 Jun 2011 00:04:55 -0700 (PDT) In-Reply-To: <4E0A4C94.7030602@netcologne.de> References: <4E0A4C94.7030602@netcologne.de> Date: Wed, 29 Jun 2011 08:06:00 -0000 Message-ID: Subject: Re: [patch, fortran] Always return malloc(1) for empty arrays in the library From: Janne Blomqvist To: Thomas Koenig Cc: "fortran@gcc.gnu.org" , gcc-patches Content-Type: text/plain; charset=UTF-8 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-06/txt/msg02188.txt.bz2 On Wed, Jun 29, 2011 at 00:50, Thomas Koenig wrote: > Hello world, > > looking at PR 49479 and other functions in the library made me realize > there are lots of places where we don't malloc one byte for empty > arrays. I'd prefer to add the zero check to runtime/memory.c (internal_malloc_size), i.e. change if (size == 0) return NULL; to if (size == 0) size = 1; Or perhaps even better would be to add that check to get_mem() instead (as a side effect making internal_malloc_size redundant), thus matching how memory allocation works in the frontend? Looking at get_mem() we actually have a small bug here; if size == 0 and malloc happens to return NULL we treat it as an error. -- Janne Blomqvist