X-Recipient: archive-cygwin AT delorie DOT com DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:to:subject:mime-version:content-type :content-transfer-encoding:date:from:in-reply-to:references :message-id; q=dns; s=default; b=ALBjiW8mhAZcg1hkT2K3jd92+eAgeJs dEfVtLzuDDSh25WQs1LZUtAvULhc+FUMYprmdiHzRLkHuoxQsX1bEekmucFX+SdE aRjVMXlstO1jTS4i/qiU5MzoSBb9nnukbiFbTfesoAGmJ+cxV6bNU35dHiKZ0zrf +cfurDHC5b2c= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:to:subject:mime-version:content-type :content-transfer-encoding:date:from:in-reply-to:references :message-id; s=default; bh=8/oZqEJzBrFh7kVd3SQF/dY+BJ0=; b=YRNSF isFDFC+Cvx6uDtxepvU6NSu90/prP7QsVpUBT4/4v3mxlZ8EuPcu4wm4ognIr3AZ AFZ2mHLrc+DXp7czNgWIxKB1znuvchDaXXPaA/ZJO2Mka9vGoKQaN+yerKK8fsBs nSoE8Mk1h37+AJqTwgZT1I246LJsRaE4q5NuWs= Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.2 required=5.0 tests=AWL,BAYES_00,FROM_STARTS_WITH_NUMS,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=no version=3.3.1 spammy=HX-Languages-Length:1379, H*u:0.9.2, H*UA:0.9.2, sus X-HELO: smtp-out-no.shaw.ca To: cygwin AT cygwin DOT com Subject: Re: malloc(0) crashing with SIGABRT MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Date: Wed, 11 Sep 2019 22:18:19 -0700 From: Kaz Kylheku <920-082-4242 AT kylheku DOT com> In-Reply-To: <749ecff2-e384-bbfe-c961-481157c73052@SystematicSw.ab.ca> References: <366918d8-b505-45be-dc28-303579f17341 AT gmail DOT com> <78e19eb7-956e-cd05-a076-e56ce347bbbe AT gmail DOT com> <749ecff2-e384-bbfe-c961-481157c73052 AT SystematicSw DOT ab DOT ca> Message-ID: <7ee0dd42337eff1b2a173d06d1cc5990@mail.kylheku.com> X-Sender: 920-082-4242 AT kylheku DOT com User-Agent: Roundcube Webmail/0.9.2 X-IsSubscribed: yes On 2019-09-11 20:59, Brian Inglis wrote: > On 2019-09-09 11:13, Petr Skočík wrote: >> There's been a twitter discussion on how different POSIX platforms >> handle malloc(0): >> https://twitter.com/sortiecat/status/1170697927804817412 . >> >> As for Cygwin, the answer appears to be "not well", but this should be >> easy to fix. > > POSIX SUS V4 2018 says: > > "RETURN VALUE > > Upon successful completion with size not equal to 0, malloc() shall > return a > pointer to the allocated space. If size is 0, either: > > A null pointer shall be returned [CX] [Option Start] and errno may be > set to > an implementation-defined value, [Option End] or > > A pointer to the allocated space shall be returned. The application > shall > ensure that the pointer is not used to access an object. > > Otherwise, it shall return a null pointer [CX] [Option Start] and set > errno to > indicate the error. [Option End]" > > The second option could be implemented by a pointer to an unmapped > page, or a > reference to an inaccessible mmap-ed area length zero. That's easy: the null pointer, plus some small offset that observes alignment, like 16. (Alignment is important even if the memory isn't accessed, because nonportable programs depend on it for other reasons, like being able to use the least significant few bits of a pointer for tagging.) -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple