Ensure result of every variant of MS_TIME_DIFF has unsigned long type
authorIvan Maidanski <ivmai@mail.ru>
Fri, 4 Jan 2019 16:55:34 +0000 (19:55 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Sat, 5 Jan 2019 09:04:37 +0000 (12:04 +0300)
(code refactoring)

Previously, MS_TIME_DIFF had the result of long type for Nintendo and
Win32 targets.

* include/private/gc_priv.h [!NO_CLOCK && BSD_TIME] (MS_TIME_DIFF): Add
comment.
* include/private/gc_priv.h [!NO_CLOCK && !BSD_TIME && (MSWIN32
|| MSWINCE || NN_PLATFORM_CTR)] (MS_TIME_DIFF): Cast result to
unsigned long (instead of long).

include/private/gc_priv.h

index 8139cee..8b495d6 100644 (file)
@@ -437,6 +437,8 @@ EXTERN_C_END
                 } while (0)
 # define MS_TIME_DIFF(a,b) ((unsigned long)((long)(a.tv_sec-b.tv_sec) * 1000 \
                                     + (long)(a.tv_usec-b.tv_usec) / 1000))
+                            /* "a" time is expected to be not earlier than  */
+                            /* "b" one; the result has unsigned long type.  */
 #elif defined(MSWIN32) || defined(MSWINCE)
 # ifndef WIN32_LEAN_AND_MEAN
 #   define WIN32_LEAN_AND_MEAN 1
@@ -450,7 +452,7 @@ EXTERN_C_END
 # else
 #   define GET_TIME(x) (void)(x = GetTickCount())
 # endif
-# define MS_TIME_DIFF(a,b) ((long)((a)-(b)))
+# define MS_TIME_DIFF(a,b) ((unsigned long)((a)-(b)))
 #elif defined(NN_PLATFORM_CTR)
 # define CLOCK_TYPE long long
   EXTERN_C_BEGIN
@@ -458,7 +460,7 @@ EXTERN_C_END
   CLOCK_TYPE n3ds_convert_tick_to_ms(CLOCK_TYPE tick);
   EXTERN_C_END
 # define GET_TIME(x) (void)(x = n3ds_get_system_tick())
-# define MS_TIME_DIFF(a,b) ((long)n3ds_convert_tick_to_ms((a)-(b)))
+# define MS_TIME_DIFF(a,b) ((unsigned long)n3ds_convert_tick_to_ms((a)-(b)))
 #else /* !BSD_TIME && !NN_PLATFORM_CTR && !MSWIN32 && !MSWINCE */
 # include <time.h>
 # if defined(FREEBSD) && !defined(CLOCKS_PER_SEC)