From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 246 invoked from network); 30 Apr 2007 03:30:02 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.8 (2007-02-13) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,FORGED_RCVD_HELO autolearn=ham version=3.1.8 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 30 Apr 2007 03:30:02 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 53178 invoked from network); 30 Apr 2007 03:29:56 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 30 Apr 2007 03:29:56 -0000 Received: (qmail 15981 invoked by alias); 30 Apr 2007 03:29:53 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 23354 Received: (qmail 15972 invoked from network); 30 Apr 2007 03:29:53 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 30 Apr 2007 03:29:53 -0000 Received: (qmail 52859 invoked from network); 30 Apr 2007 03:29:53 -0000 Received: from g.primenet.com.au (203.24.36.10) by a.mx.sunsite.dk with SMTP; 30 Apr 2007 03:29:50 -0000 Received: (qmail 3440 invoked by uid 100); 30 Apr 2007 03:29:48 -0000 Date: Mon, 30 Apr 2007 13:29:48 +1000 From: Geoff Wing To: Zsh Hackers Subject: Re: PATCH: and query for malloc(0). Message-ID: <20070430032948.GA2612@primenet.com.au> References: <200704272135.l3RLZE1d005051@pwslaptop.csr.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200704272135.l3RLZE1d005051@pwslaptop.csr.com> Organization: PrimeNet Computer Consultancy User-Agent: Mutt/1.5.15 (2007-04-06) On Saturday 2007-04-28 07:36 +1000, Peter Stephenson output: :Playing with POSIX regexes, I found some errors coming from zsh's memory :allocation with debugging on. These turned out to resolve to some :malloc()s and free()s for zero length and the following oddity in :malloc(): : /* some systems want malloc to return the highest valid address plus one : if it is called with an argument of zero */ : if (!size) : return (MALLOC_RET_T) m_high; This appeared in zsh 2.5. I don't know the origin. It's a bit weird as different systems will do conflicting things with it. NetBSD returns NULL An older Solaris man page says for malloc(): "a unique pointer to the arena is returned"; and for bsdmalloc(): "a non-NULL pointer. ... These pointers should not be dereferenced." SUS says: "If size is 0, either a null pointer or a unique pointer that can be successfully passed to free() shall be returned." Given the above, I guess the patch is a reasonable fix. We are not actually calling malloc(0) in-house, are we? Regards, Geoff