From abe403b1902de63cfb404c916d62bc28c05d4096 Mon Sep 17 00:00:00 2001 From: Alexander Kanavin Date: Tue, 15 Aug 2023 13:55:06 +0200 Subject: [PATCH] various: timespec/timeval.tv_sec is time_t, not long, according to POSIX This matters on 32 bit systems configured with 64 bit time_t (so they survive beyond 2038). Casting them to long is causing loss of bits and badly mismatched time data. Signed-off-by: Alexander Kanavin --- AUTHORS | 1 + dist/threads-shared/lib/threads/shared.pm | 2 +- dist/threads-shared/shared.xs | 2 +- doio.c | 4 ++-- pp_sys.c | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/AUTHORS b/AUTHORS index 521d65c5725f..8dd790d9abcb 100644 --- a/AUTHORS +++ b/AUTHORS @@ -72,6 +72,7 @@ Alexander Foken Alexander Gernler Alexander Gough Alexander Hartmaier +Alexander Kanavin Alexander Klimov Alexander Nikolov Alexander Smishlajev diff --git a/dist/threads-shared/lib/threads/shared.pm b/dist/threads-shared/lib/threads/shared.pm index 6e67acd438fc..fef27aba11aa 100644 --- a/dist/threads-shared/lib/threads/shared.pm +++ b/dist/threads-shared/lib/threads/shared.pm @@ -8,7 +8,7 @@ use Config; use Scalar::Util qw(reftype refaddr blessed); -our $VERSION = '1.68'; # Please update the pod, too. +our $VERSION = '1.69'; # Please update the pod, too. my $XS_VERSION = $VERSION; $VERSION = eval $VERSION; diff --git a/dist/threads-shared/shared.xs b/dist/threads-shared/shared.xs index f78542d9e179..938f963f5e07 100644 --- a/dist/threads-shared/shared.xs +++ b/dist/threads-shared/shared.xs @@ -697,7 +697,7 @@ Perl_sharedsv_cond_timedwait(perl_cond *cond, perl_mutex *mut, double abs) struct timespec ts; int got_it = 0; - ts.tv_sec = (long)abs; + ts.tv_sec = (time_t)abs; abs -= (NV)ts.tv_sec; ts.tv_nsec = (long)(abs * 1000000000.0); diff --git a/doio.c b/doio.c index 52c262c44062..34cdf968d933 100644 --- a/doio.c +++ b/doio.c @@ -2872,9 +2872,9 @@ nothing in the core. else { Zero(&utbuf, sizeof utbuf, char); #ifdef HAS_FUTIMES - utbuf[0].tv_sec = (long)SvIV(accessed); /* time accessed */ + utbuf[0].tv_sec = (time_t)SvIV(accessed); /* time accessed */ utbuf[0].tv_usec = 0; - utbuf[1].tv_sec = (long)SvIV(modified); /* time modified */ + utbuf[1].tv_sec = (time_t)SvIV(modified); /* time modified */ utbuf[1].tv_usec = 0; #elif defined(BIG_TIME) utbuf.actime = (Time_t)SvNV(accessed); /* time accessed */ diff --git a/pp_sys.c b/pp_sys.c index cd420b10287e..2ba0642dcd10 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -1228,7 +1228,7 @@ PP_wrapped(pp_sselect, 4, 0) value = SvNV_nomg(sv); if (value < 0.0) value = 0.0; - timebuf.tv_sec = (long)value; + timebuf.tv_sec = (time_t)value; value -= (NV)timebuf.tv_sec; timebuf.tv_usec = (long)(value * 1000000.0); }