From 03cd9c09ff147ae19616ac65d3c0305329818c92 Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Wed, 14 Feb 2007 16:17:19 +0000 Subject: [PATCH] fix to getUSecOfDay(): arithmetic was overflowing --- include/HsBase.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/HsBase.h b/include/HsBase.h index 09693cb..45e2d39 100644 --- a/include/HsBase.h +++ b/include/HsBase.h @@ -724,7 +724,10 @@ INLINE HsWord64 getUSecOfDay(void) { struct timeval tv; gettimeofday(&tv, (struct timezone *) NULL); - return (tv.tv_sec * 1000000 + tv.tv_usec); + // Don't forget to cast *before* doing the arithmetic, otherwise + // the arithmetic happens at the type of tv_sec, which is probably + // only 'int'. + return ((HsWord64)tv.tv_sec * 1000000 + (HsWord64)tv.tv_usec); } INLINE void setTimevalTicks(struct timeval *p, HsWord64 usecs) -- 1.7.10.4