Skip to content

Commit 5c2d5de

Browse files
committed
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.
1 parent 79c6bd0 commit 5c2d5de

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

dist/threads-shared/shared.xs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ Perl_sharedsv_cond_timedwait(perl_cond *cond, perl_mutex *mut, double abs)
697697
struct timespec ts;
698698
int got_it = 0;
699699

700-
ts.tv_sec = (long)abs;
700+
ts.tv_sec = (time_t)abs;
701701
abs -= (NV)ts.tv_sec;
702702
ts.tv_nsec = (long)(abs * 1000000000.0);
703703

doio.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2874,9 +2874,9 @@ nothing in the core.
28742874
else {
28752875
Zero(&utbuf, sizeof utbuf, char);
28762876
#ifdef HAS_FUTIMES
2877-
utbuf[0].tv_sec = (long)SvIV(accessed); /* time accessed */
2877+
utbuf[0].tv_sec = (time_t)SvIV(accessed); /* time accessed */
28782878
utbuf[0].tv_usec = 0;
2879-
utbuf[1].tv_sec = (long)SvIV(modified); /* time modified */
2879+
utbuf[1].tv_sec = (time_t)SvIV(modified); /* time modified */
28802880
utbuf[1].tv_usec = 0;
28812881
#elif defined(BIG_TIME)
28822882
utbuf.actime = (Time_t)SvNV(accessed); /* time accessed */

pp_sys.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,7 @@ PP(pp_sselect)
12281228
value = SvNV_nomg(sv);
12291229
if (value < 0.0)
12301230
value = 0.0;
1231-
timebuf.tv_sec = (long)value;
1231+
timebuf.tv_sec = (time_t)value;
12321232
value -= (NV)timebuf.tv_sec;
12331233
timebuf.tv_usec = (long)(value * 1000000.0);
12341234
}

0 commit comments

Comments
 (0)