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 87e73e5b01
commit a63c508402
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
1 changed files with 7 additions and 1 deletions

View File

@ -392,7 +392,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 *