com php-src: Fixed possible precision loss in microtime: win32/time.c
| From: | Anatol Belski | Date: | Sat, 23 Mar 2013 16:40:06 +0000 |
| Subject: | com php-src: Fixed possible precision loss in microtime: win32/time.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-71697@lists.php.net to get a copy of this message | ||
Commit: b022e54bd100a914417e216d0872d3e67edecaf9
Author: Anatol Belski <ab@php.net> Sat, 23 Mar 2013 17:40:06 +0100
Parents: bb935ff8dc65c52efea6aae6697a806dc86c8580
Branches: PHP-5.3 PHP-5.4 PHP-5.5 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=b022e54bd100a914417e216d0872d3e67edecaf9
Log:
Fixed possible precision loss in microtime
This is related to the fix for bug #64370. MSVC natively supports __int64 type,
so calculating with 32 bit ints is neither necessary nor reliable. Therefore
an older piece of code is reused.
Bugs:
https://bugs.php.net/64370
Changed paths:
M win32/time.c
Diff:
diff --git a/win32/time.c b/win32/time.c
index 77e4504..7553974 100644
--- a/win32/time.c
+++ b/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;
}