Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'PHP-5.4' into PHP-5.5

* PHP-5.4:
  Fixed possible precision loss in microtime
  • Loading branch information...
commit 2e00f7611c29713b7b53ee9006892fc9576fb788 2 parents defb08c + 3654ff7
@weltling weltling authored
Showing with 13 additions and 6 deletions.
  1. +13 −6 win32/time.c
View
19 win32/time.c
@@ -50,6 +50,7 @@ int getfilesystemtime(struct timeval *tv)
FILETIME ft;
unsigned __int64 ff = 0;
MyGetSystemTimeAsFileTime timefunc;
+ ULARGE_INTEGER fft;
timefunc = get_time_func();
if (timefunc) {
@@ -58,14 +59,20 @@ int getfilesystemtime(struct timeval *tv)
GetSystemTimeAsFileTime(&ft);
}
- ff |= ft.dwHighDateTime;
- ff <<= 32;
- ff |= ft.dwLowDateTime;
- ff /= 10; /* convert to microseconds */
+ /*
+ * Do not cast a pointer to a FILETIME structure to either a
+ * ULARGE_INTEGER* or __int64* value because it can cause alignment faults on 64-bit Windows.
+ * via http://technet.microsoft.com/en-us/library/ms724284(v=vs.85).aspx
+ */
+ fft.HighPart = ft.dwHighDateTime;
+ fft.LowPart = ft.dwLowDateTime;
+ ff = fft.QuadPart;
+
+ ff /= 10Ui64; /* convert to microseconds */
ff -= 11644473600000000Ui64; /* convert to unix epoch */
- tv->tv_sec = (long)(ff / 1000000UL);
- tv->tv_usec = (long)(ff % 1000000UL);
+ tv->tv_sec = (long)(ff / 1000000Ui64);
+ tv->tv_usec = (long)(ff % 1000000Ui64);
return 0;
}
Please sign in to comment.
Something went wrong with that request. Please try again.