delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2019/09/12/00:00:06

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:from:subject:reply-to:to:references:message-id
:date:mime-version:in-reply-to:content-type
:content-transfer-encoding; q=dns; s=default; b=f+0CTAdx2gfJgrL2
wUrgZVHfIuMtdxmR4SUWDVpH8y1wYQ71gfbfE69LbQn1ikto8bRfg3YSKgIfkNxQ
bM8N/6cdVFafjTAwv/33X3GkYU40Qonw9x8X37XFj9IGOs03C4EMZzlff+TkpNYm
A+XGBgITpqlLXiZYewplNvPLt6I=
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:from:subject:reply-to:to:references:message-id
:date:mime-version:in-reply-to:content-type
:content-transfer-encoding; s=default; bh=fNWWZ408/LvU0ta+jUVhA8
Thj8s=; b=UgKmZ9MD7HwycntAfrM9xYk+u2P820SoPTYQp1bKct9k1IfheKOoq3
DvD4wG4qAVMJR6SBnVYUybX9i3VkDfYotYTUyChcrG95xn6OW0OAT/vQVDFZiL5t
ILYck1/OGrVWak5J+jUknJvsDz0gf58iB6/v+8m/KRM47EW18f7C8=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
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=-2.5 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=sus, k, inaccessible, RETURN
X-HELO: smtp-out-so.shaw.ca
From: Brian Inglis <Brian DOT Inglis AT SystematicSw DOT ab DOT ca>
Subject: Re: malloc(0) crashing with SIGABRT
Reply-To: Brian DOT Inglis AT SystematicSw DOT ab DOT ca
To: cygwin AT cygwin DOT com
References: <366918d8-b505-45be-dc28-303579f17341 AT gmail DOT com> <78e19eb7-956e-cd05-a076-e56ce347bbbe AT gmail DOT com>
Openpgp: preference=signencrypt
Message-ID: <749ecff2-e384-bbfe-c961-481157c73052@SystematicSw.ab.ca>
Date: Wed, 11 Sep 2019 21:59:08 -0600
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0
MIME-Version: 1.0
In-Reply-To: <78e19eb7-956e-cd05-a076-e56ce347bbbe@gmail.com>
X-IsSubscribed: yes

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.

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

This email may be disturbing to some readers as it contains
too much technical detail. Reader discretion is advised.

--
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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright 2019   by DJ Delorie     Updated Jul 2019