Fix BSD_TIME variant of MS_TIME_DIFF for the case of a.tv_usec < b.tv_usec
authorIvan Maidanski <ivmai@mail.ru>
Fri, 4 Jan 2019 16:37:50 +0000 (19:37 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Sat, 5 Jan 2019 09:04:37 +0000 (12:04 +0300)
(fix of commit 6b2796b69)

* include/private/gc_priv.h [!NO_CLOCK && BSD_TIME] (MS_TIME_DIFF):
Cast the result of a.tv_usec-b.tv_usec to long (so that the result of
the division should be negative if a.tv_usec is less than b.tv_usec).

include/private/gc_priv.h

index 3027c8f..8139cee 100644 (file)
@@ -435,8 +435,8 @@ EXTERN_C_END
                   getrusage(RUSAGE_SELF, &rusage); \
                   x = rusage.ru_utime; \
                 } while (0)
-# define MS_TIME_DIFF(a,b) ((unsigned long)(a.tv_sec - b.tv_sec) * 1000 \
-                            + (unsigned long)(a.tv_usec - b.tv_usec) / 1000)
+# define MS_TIME_DIFF(a,b) ((unsigned long)((long)(a.tv_sec-b.tv_sec) * 1000 \
+                                    + (long)(a.tv_usec-b.tv_usec) / 1000))
 #elif defined(MSWIN32) || defined(MSWINCE)
 # ifndef WIN32_LEAN_AND_MEAN
 #   define WIN32_LEAN_AND_MEAN 1