core: Avoid Floating point exception dividing negative numbers.

* src/posix.c (seconds_and_nanoseconds_to_long): Use unsigned division.
This commit is contained in:
Jan (janneke) Nieuwenhuizen 2021-01-01 09:46:20 +01:00
parent ca64fa5e78
commit a523493634
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
1 changed files with 8 additions and 2 deletions

View File

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2016,2017,2018,2019,2020,2021 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
@ -411,7 +411,13 @@ gettimeofday_ () /*:((name . "gettimeofday")) */
long
seconds_and_nanoseconds_to_long (long s, long ns)
{
return s * TIME_UNITS_PER_SECOND + ns / (1000000000 / TIME_UNITS_PER_SECOND);
size_t uns = ns;
if (ns < 0)
{
uns = - ns;
return s * TIME_UNITS_PER_SECOND - uns / (1000000000 / TIME_UNITS_PER_SECOND);
}
return s * TIME_UNITS_PER_SECOND + uns / (1000000000 / TIME_UNITS_PER_SECOND);
}
struct scm *