Skip to content

Commit

Permalink
avoid truncating time values when long is smaller than time_t
Browse files Browse the repository at this point in the history
long is only 32-bits on x64 Win32, but time_t is 64-bits.  This was warning:

POSIX.xs(1777) : warning C4244: 'initializing' : conversion from 'time_t' to 'const long', possible loss of data

The check against (time_t)-1 is the approved check from ANSI C 89 and
99.
  • Loading branch information
tonycoz committed Jan 18, 2012
1 parent 33f8979 commit e2054bc
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ext/POSIX/POSIX.xs
Original file line number Diff line number Diff line change
Expand Up @@ -1774,8 +1774,8 @@ asctime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = -1)
mytm.tm_yday = yday;
mytm.tm_isdst = isdst;
if (ix) {
const long result = mktime(&mytm);
if (result == -1)
const time_t result = mktime(&mytm);
if (result == (time_t)-1)
SvOK_off(TARG);
else if (result == 0)
sv_setpvn(TARG, "0 but true", 10);
Expand Down

0 comments on commit e2054bc

Please sign in to comment.