From: Carlos O'Donell <carlos@redhat.com>
To: Torvald Riegel <triegel@redhat.com>,
Mark Thompson <mark.thompson@starleaf.com>
Cc: Szabolcs Nagy <szabolcs.nagy@arm.com>,
GNU C Library <libc-alpha@sourceware.org>, nd <nd@arm.com>
Subject: Re: [PATCH] Don't divide by zero when trying to destroy an uninitialised barrier.
Date: Wed, 27 Apr 2016 14:27:00 -0000 [thread overview]
Message-ID: <5720CC4F.6060905@redhat.com> (raw)
In-Reply-To: <1461255829.3869.578.camel@localhost.localdomain>
On 04/21/2016 12:23 PM, Torvald Riegel wrote:
> On Wed, 2016-04-20 at 20:16 +0100, Mark Thompson wrote:
>> On 20/04/16 18:03, Szabolcs Nagy wrote:
>>> On 20/04/16 17:48, Mark Thompson wrote:
>>>> ---
>>>> nptl/pthread_barrier_destroy.c | 9 +++++++++
>>>> 1 file changed, 9 insertions(+)
>>>>
>>>> diff --git a/nptl/pthread_barrier_destroy.c b/nptl/pthread_barrier_destroy.c
>>>> index 92d2027..d114084 100644
>>>> --- a/nptl/pthread_barrier_destroy.c
>>>> +++ b/nptl/pthread_barrier_destroy.c
>>>> @@ -36,6 +36,15 @@ pthread_barrier_destroy (pthread_barrier_t *barrier)
>>>> they have exited as well. To get the notification, pretend that we have
>>>> reached the reset threshold. */
>>>> unsigned int count = bar->count;
>>>> +
>>>> + /* For an initialised barrier, count must be greater than zero here. An
>>>> + uninitialised barrier may still have zero, however, and in this case it is
>>>> + preferable to fail immediately rather than to invoke undefined behaviour
>>>> + by dividing by zero on the next line. (POSIX allows the implementation to
>>>> + diagnose invalid state and return EINVAL in this case.) */
>>>> + if (__glibc_unlikely (count == 0))
>>>> + return EINVAL;
>>>> +
>>>
>>> this case is undefined behaviour in posix, and
>>> i think the best way to handle that is crashing.
>>> (because no behaviour can be portably relied upon)
>>
>> The undefined behaviour is not necessarily crashing - systems which
>> do not trap on divide by zero (such as aarch64) will do something
>> else, such as returning success or hanging forever. Would you
>> prefer an abort() be added to make the behavior consistent?
>
> IMO, abort() would be better than returning EINVAL. See
> https://sourceware.org/glibc/wiki/Style_and_Conventions#Bugs_in_the_user_program
Agreed.
It's easy to detect. We should abort().
--
Cheers,
Carlos.
prev parent reply other threads:[~2016-04-27 14:27 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-20 16:49 Mark Thompson
2016-04-20 17:03 ` Szabolcs Nagy
2016-04-20 19:16 ` Mark Thompson
2016-04-20 19:47 ` Adhemerval Zanella
2016-04-26 14:38 ` Florian Weimer
2016-04-26 14:44 ` Adhemerval Zanella
2016-04-26 17:24 ` Mike Frysinger
2016-04-26 18:04 ` Torvald Riegel
2016-04-26 19:47 ` Adhemerval Zanella
2016-04-21 16:24 ` Torvald Riegel
2016-04-27 14:27 ` Carlos O'Donell [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5720CC4F.6060905@redhat.com \
--to=carlos@redhat.com \
--cc=libc-alpha@sourceware.org \
--cc=mark.thompson@starleaf.com \
--cc=nd@arm.com \
--cc=szabolcs.nagy@arm.com \
--cc=triegel@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).