From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13707 invoked by alias); 9 Jul 2018 17:17:21 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 13698 invoked by uid 89); 9 Jul 2018 17:17:20 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 spammy=Bottom, H*r:sk:smtp-ou, wish X-HELO: smtp-out-so.shaw.ca Received: from smtp-out-so.shaw.ca (HELO smtp-out-so.shaw.ca) (64.59.136.139) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 09 Jul 2018 17:17:18 +0000 Received: from [192.168.1.100] ([24.64.240.204]) by shaw.ca with ESMTP id cZm9fylLBbP3IcZmAfefcI; Mon, 09 Jul 2018 11:16:39 -0600 Reply-To: Brian.Inglis@SystematicSw.ab.ca Subject: Re: FPE in localtime.cc To: cygwin@cygwin.com References: <20180709164947.GE27673@calimero.vinschen.de> From: Brian Inglis Openpgp: preference=signencrypt Message-ID: Date: Mon, 09 Jul 2018 17:17:00 -0000 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: <20180709164947.GE27673@calimero.vinschen.de> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2018-07/txt/msg00083.txt.bz2 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 > #include > #include > > #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? > 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 ;^> -- Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada -- 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