delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2018/07/09/12:50:04

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:date:from:to:subject:message-id:reply-to
:references:mime-version:content-type:in-reply-to; q=dns; s=
default; b=TmaR2cn9YJ9rex1pPPe+brzR1Y+MwgeTBNndHXJ0+lv9/0xD45mhn
yxt4T9fjCJu2yuO6aDEZh8/8VkbJcsFjZUCqItrGmq3p7DPV8uJO7gsmfcKbSpY+
fBY6OwlFlqor8GxuE9j0bJtB0sQ/ZdGT35Xjo8CUCio1EcaQniB9Z0=
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:date:from:to:subject:message-id:reply-to
:references:mime-version:content-type:in-reply-to; s=default;
bh=xhxL2iqSm3UeSwNx/fuZpN79xdE=; b=oI7sOni18h1en6wWTtkzbetBR7Zy
PR4SuqDXEk/imH8RxFe/ahvlqQusxUH9gwqshoot8qaLklbCkkaGuy+k9jZTrOoT
W3kw8LLhu4dPZIH3Zc1Gdne+2XoTTjjdlfuuT1Y9iBwXbiEnDmmlmz8VizujMRZD
n9137i7DHeHChUI=
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=-101.3 required=5.0 tests=AWL,BAYES_00,GOOD_FROM_CORINNA_CYGWIN,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=nih, NLM, NIH, nlm
X-HELO: mout.kundenserver.de
Date: Mon, 9 Jul 2018 18:49:47 +0200
From: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: FPE in localtime.cc
Message-ID: <20180709164947.GE27673@calimero.vinschen.de>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
References: <CY4PR09MB1302CB30716988BB7BB61EF3A5440 AT CY4PR09MB1302 DOT namprd09 DOT prod DOT outlook DOT com>
MIME-Version: 1.0
In-Reply-To: <CY4PR09MB1302CB30716988BB7BB61EF3A5440@CY4PR09MB1302.namprd09.prod.outlook.com>
User-Agent: Mutt/1.9.2 (2017-12-15)

--S1BNGpv0yoYahz37
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Jul  9 15:47, Lavrentiev, Anton (NIH/NLM/NCBI) [C] wrote:
> Hello,
>=20
> the following sample coredumps with FPE at localhost.cc:1962 with the lat=
est snapshot (6/29/2018):
>=20
> #define _GNU_SOURCE
> #include <fenv.h>
> #include <time.h>
> #include <stdio.h>
>=20
> static time_t s_Time;
>=20
> static void fun(void)
> {
>   char buf[40];
>   strftime(buf, sizeof(buf), "%m/%d/%y %H:%M:%S", localtime(&s_Time));
>   printf("%s\n", buf);
> }
>=20
> int main()
> {
>   feenableexcept(FE_ALL_EXCEPT);
>   time(&s_Time);
>   fun();
> }
>=20
> $ cat a.exe.stackdump
> Exception: STATUS_FLOAT_INEXACT_RESULT at rip=3D001800BBA24
> rax=3D000000000000016D rbx=3D000000005B43498E rcx=3D00000000000001EC
> rdx=3D1845C8A0CE512957 rsi=3D0000000051EB851F rdi=3D2CC3D8D4A245F203
> r8 =3D0000000000F92B80 r9 =3D00000000FFFFFFED r10=3D00000000000007E2
> r11=3D000000000000000C r12=3D00000000FFFFFFFF r13=3D0000000080000000
> r14=3D00000000000000BD r15=3D00000000000007E2
> rbp=3D000000007FFFFFFF rsp=3D00000000FFFFCA70
> program=3DC:\Cygwin64\...\a.exe, pid 14232, thread main
> cs=3D0033 ds=3D002B es=3D002B fs=3D0053 gs=3D002B ss=3D002B
>=20
> Removing the first line of the main() function lets the program run succe=
ssfully.
> The same code runs fine unmodified on Linux.
>=20
> $ gcc -Wall sample.c -lm
> $ ./a.out
> 07/09/18 11:44:26
>=20
> Any ideas?

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 =3D argc > 1 ? strtol (argv[1], NULL, 10) : 189;
    long seconds =3D 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.

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.


Corinna

--=20
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

--S1BNGpv0yoYahz37
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEEoVYPmneWZnwT6kwF9TYGna5ET6AFAltDkisACgkQ9TYGna5E
T6Dk+w/7B1XN2z/4VeH+HRe1IkLqjq3qeAqffqaUZO+PC9K/i+w/7DLYEx7su7Og
UCEuclg1fLHeClrkdvNMbYSfYVA93ZgNo4GCQ9VgmYmVeBWJhAlh+GUOI5pHtali
2kelu/s+yvoFkjnfe7/G7JJT8FaLwx8B1KkRA/j5tJ8fiVqFff1oGffAZ3MBq9L7
7JA8bHt1tBXrihVNC6/ra/rOFtFRXn3PZWB1MdgewkWqwAfmC/mTofDl4Rs+9Rit
NbDoHkM9edqulz8EJVub181AmNAPzg56hOQ1czVP7IUpa4wpi7rIkOpTL6K0S2i7
uSbBb1Ide1JkUBk9/ivjgJoNcMSH4A/UExQv15MaGIIhWRr0RmKfFQmPyJkNJT71
iMhjl0Rso/irFti2a9nKY0t0/URED1v7dU+oFisageNOOVCmdhvuh45dA02aHrtK
1/J6v4vlX8w7QoiUdrtKcqQ4OohfssN2cYct5JrbsEnjVRdZ6HTC8/BrL4n9M/ay
IZhktrgkW2xmTxw6AEzoR+Txfsc2rtNbYaEcP/Fx81ci7DlFCR7g1i/mJb3R73WI
frqp9n58W1T5TBwFwoNBu+yyiIkf7pyy/Ry73OLgvz0EmI3fwXghtb3jzbx/jXPZ
U1FkXO5XpQUaQ7ByO07qWTwAZcPLcG54NSzrTjnPj4j70+Fz6eI=
=qUir
-----END PGP SIGNATURE-----

--S1BNGpv0yoYahz37--

- Raw text -


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