Skip to content

Commit

Permalink
various: timespec/timeval.tv_sec is time_t, not long, according to POSIX
Browse files Browse the repository at this point in the history
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 <alex@linutronix.de>
  • Loading branch information
Alexander Kanavin authored and khwilliamson committed Aug 21, 2023
1 parent 19a602a commit abe403b
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Alexander Foken
Alexander Gernler <alexander_gernler@genua.de>
Alexander Gough <alex-p5p@earth.li>
Alexander Hartmaier <abraxxa@cpan.org>
Alexander Kanavin <alex@linutronix.de>
Alexander Klimov <ask@wisdom.weizmann.ac.il>
Alexander Nikolov <sasho648@gmail.com>
Alexander Smishlajev <als@turnhere.com>
Expand Down
2 changes: 1 addition & 1 deletion dist/threads-shared/lib/threads/shared.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion dist/threads-shared/shared.xs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions doio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion pp_sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit abe403b

Please sign in to comment.