Module: wine Branch: master Commit: 1d35db9f570490b664f97d3b7e5152be4f07fcb3 URL: http://source.winehq.org/git/wine.git/?a=commit;h=1d35db9f570490b664f97d3b7e...
Author: Piotr Caban piotr@codeweavers.com Date: Tue Oct 17 17:08:15 2017 +0200
msvcp120: Fix _Xtime_diff_to_millis2 overflow behavior.
Signed-off-by: Piotr Caban piotr@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/msvcp90/misc.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/dlls/msvcp90/misc.c b/dlls/msvcp90/misc.c index 1dcc590..9f26a48 100644 --- a/dlls/msvcp90/misc.c +++ b/dlls/msvcp90/misc.c @@ -362,6 +362,7 @@ void __thiscall _Container_base12__Swap_all( #define TICKS_1601_TO_1970 (SECS_1601_TO_1970 * TICKSPERSEC) #define NANOSEC_PER_MILLISEC 1000000 #define MILLISEC_PER_SEC 1000 +#define NANOSEC_PER_SEC (NANOSEC_PER_MILLISEC * MILLISEC_PER_SEC)
typedef int MSVCRT_long;
@@ -401,16 +402,24 @@ int __cdecl xtime_get(xtime* t, int unknown) /* _Xtime_diff_to_millis2 */ MSVCRT_long __cdecl _Xtime_diff_to_millis2(const xtime *t1, const xtime *t2) { - __time64_t diff_sec; - MSVCRT_long diff_nsec, ret; + LONGLONG diff_sec, diff_nsec;
TRACE("(%p, %p)\n", t1, t2);
diff_sec = t1->sec - t2->sec; diff_nsec = t1->nsec - t2->nsec; - ret = diff_sec * MILLISEC_PER_SEC + - (diff_nsec + NANOSEC_PER_MILLISEC - 1) / NANOSEC_PER_MILLISEC; - return ret > 0 ? ret : 0; + + diff_sec += diff_nsec / NANOSEC_PER_SEC; + diff_nsec %= NANOSEC_PER_SEC; + if (diff_nsec < 0) { + diff_sec -= 1; + diff_nsec += NANOSEC_PER_SEC; + } + + if (diff_sec<0 || (diff_sec==0 && diff_nsec<0)) + return 0; + return diff_sec * MILLISEC_PER_SEC + + (diff_nsec + NANOSEC_PER_MILLISEC - 1) / NANOSEC_PER_MILLISEC; }
/* _Xtime_diff_to_millis */