This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: malloc(0) crashing with SIGABRT
- From: Brian Inglis <Brian dot Inglis at SystematicSw dot ab dot ca>
- To: cygwin at cygwin dot com
- Date: Wed, 11 Sep 2019 21:59:08 -0600
- Subject: Re: malloc(0) crashing with SIGABRT
- References: <366918d8-b505-45be-dc28-303579f17341@gmail.com> <78e19eb7-956e-cd05-a076-e56ce347bbbe@gmail.com>
- Reply-to: Brian dot Inglis at SystematicSw dot ab dot ca
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