X-Recipient: archive-cygwin@delorie.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:subject:to:references:from:message-id:date
	:mime-version:in-reply-to:content-type
	:content-transfer-encoding; q=dns; s=default; b=wF0CWtZZnlFaE2sj
	b+LzhSDKw7Xrm565q38GrIdglOu9CiDB8YnRLC+PRELNiIsVDYTYbvbRuT+sM4Pb
	dtampavUHwyynP4U/iyzfxx3SYhMzh0Qm+143/gs/ZlrbidV1CnuSsBBLBB+eN1s
	v4OTyLSCCSUcqo2ZkseUSUr2390=
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:subject:to:references:from:message-id:date
	:mime-version:in-reply-to:content-type
	:content-transfer-encoding; s=default; bh=B7d6h6Q0gm4CBb3OlbuCg2
	7rcUY=; b=hjdrhYeMBrsIQ6trxHn7Ut47megV31E78iElMCYiku1t6zLiSI6Egw
	lH1BO+QlXyKDk86DC0M6ubM23zFqhAB06ZFAmoo6ff/mZyy8dKzRc+w9exyn8gq5
	sWKVqgTr+lNfKrpxTJ4EyiLR8iTvHNN2FaCbg/l1+xRL6K4s8FjCs=
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
Authentication-Results: sourceware.org; auth=none
X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=
X-HELO: mail-it0-f41.google.com
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;        d=gmail.com; s=20161025;        h=subject:to:references:from:openpgp:autocrypt:message-id:date         :user-agent:mime-version:in-reply-to:content-language         :content-transfer-encoding;        bh=P1IPd+POg9hSo7gCDKhfHMdkJGr1Z2cLVMs18leLZek=;        b=G0qEGt3NWH3PXRXllQ3c+N2kdbQgdZppjoS0dMVjJY2bbwP/xaW40/Mg2WSj6uVu61         V03xovfgwGLQM3p7Nurb3iJQSdXCofb2tDynI8yvpeyg6w36VvCzCs3kvzZWJm6TyOBh         8ysFn6Sy80Te20h15hpY90xRzeAQcAzVA7W385f0Xtub0YAeXErCcMhD+BIIzpz55dCW         9+vEwIYXruIoG1DdXOXm6x5W5JOPPrxQDhqrZ/uHmg56IqXH7frkZpuP7Is/aOKHeR65         elEoT4XERjKM+DgKCH2POJm0fnUuc9He6gABYgS9lkqmYGzqB+3ilnHggcgvBrmiVXLv         +09w==
Subject: Re: FPE in localtime.cc
To: cygwin@cygwin.com
References: <CY4PR09MB1302CB30716988BB7BB61EF3A5440@CY4PR09MB1302.namprd09.prod.outlook.com> <20180709164947.GE27673@calimero.vinschen.de> <cf7088aa-9cb5-bc43-1bf2-6acc0603b57b@SystematicSw.ab.ca> <20180709190729.GF27673@calimero.vinschen.de>
From: cyg Simple <cygsimple@gmail.com>
Openpgp: preference=signencrypt
Message-ID: <f9d5e7f4-7a33-9868-efaf-986eaa4baa2f@gmail.com>
Date: Tue, 10 Jul 2018 09:35:11 -0400
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.0
MIME-Version: 1.0
In-Reply-To: <20180709190729.GF27673@calimero.vinschen.de>
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-IsSubscribed: yes

On 7/9/2018 3:07 PM, Corinna Vinschen wrote:
> On Jul  9 11:16, Brian Inglis wrote:
>> On 2018-07-09 10:49, Corinna Vinschen wrote:
>>> On Jul  9 15:47, Lavrentiev, Anton (NIH/NLM/NCBI) [C] wrote:
>>>> Hello,
>>>>
>>>> the following sample coredumps with FPE at localhost.cc:1962 with the latest snapshot (6/29/2018):
>> ...
>>> You can simplify your testcase by not calling any time functions:
>>>
>>>   #define _GNU_SOURCE
>>>   #include <fenv.h>
>>>   #include <stdio.h>
>>>   #include <stdlib.h>
>>>
>>>   #define SECSPERDAY 86400
>>>
>>>   int main(int argc, char **argv)
>>>   {
>>>     feenableexcept(FE_ALL_EXCEPT);
>>>     long tdays = argc > 1 ? strtol (argv[1], NULL, 10) : 189;
>>>     long seconds = tdays * SECSPERDAY + 0.5;
>>>     printf ("%ld\n", seconds);
>>>   }
>>>
>>> This generates a SIGFPE on Linux as well.
>>>
>>> The line computing seconds is the same line as used by the localtime
>>> function.  Cygwin shares the entire localtime code with the various
>>> BSDs, so I guess they would have the same problem.
>> What is that line meant to do? Am I missing something?
>> It should be the equivalent of (tdays*SECSPERDAY*2 + 1)/2!
>> It converts an integer value to double, adds 1/2, and throws it away on
>> conversion back, unless the intermediate has insufficient mantissa bits, in
>> which case, it loses the low bits?
> 
> You may want to ask the original author why he used FP arithmetic in
> this place.  Maybe it's a way to avoid integer overflow.  I'm reluctant
> to change this given that this code is still used in BSD as well.
> 

I don't see a fetestexcept() being used.  Setting all the bits is
definitely going to raise an exception.

>>> Bottom line is, don't bulk enable FP exceptions, but only if you really
>>> need it for certain parts of your code.  Don't expect library functions
>>> to be SIGFPE clean under all circumstances.
>>
>> Maybe selectively enable specific FPEs to check for where needed.
>> Or be careful what you wish for, as you just might get a lot more than you
>> bargained for ;^>
> 
> That's what I meant.

Yes, see:
https://en.cppreference.com/w/c/numeric/fenv/FE_exceptions

-- 
cyg Simple

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

