From 5f845f7519ccb85aa5ff8ae1bba6b15046d3022a Mon Sep 17 00:00:00 2001 From: Koichiro IWAO Date: Tue, 3 Apr 2018 16:52:12 +0900 Subject: [PATCH] common: g_time[23]() should be long long signed int causes overflow since it returns epoch time in msec. --- common/os_calls.c | 10 +++++----- common/os_calls.h | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/common/os_calls.c b/common/os_calls.c index e7fc144c..a3a8c716 100644 --- a/common/os_calls.c +++ b/common/os_calls.c @@ -3538,24 +3538,24 @@ g_time1(void) /*****************************************************************************/ /* returns the number of milliseconds since the machine was started. */ -int +long long g_time2(void) { #if defined(_WIN32) - return (int)GetTickCount(); + return (long long)GetTickCount(); #else struct tms tm; clock_t num_ticks = 0; g_memset(&tm, 0, sizeof(struct tms)); num_ticks = times(&tm); - return (int)(num_ticks * 10); + return (long long)(num_ticks * 10); #endif } /*****************************************************************************/ /* returns time in milliseconds, uses gettimeofday does not work in win32 */ -int +long long g_time3(void) { #if defined(_WIN32) @@ -3564,7 +3564,7 @@ g_time3(void) struct timeval tp; gettimeofday(&tp, 0); - return (tp.tv_sec * 1000) + (tp.tv_usec / 1000); + return ((long long)tp.tv_sec * 1000) + ((long long)tp.tv_usec / 1000); #endif } diff --git a/common/os_calls.h b/common/os_calls.h index e42e95bd..c04cbba6 100644 --- a/common/os_calls.h +++ b/common/os_calls.h @@ -174,8 +174,8 @@ int g_getuser_info(const char* username, int* gid, int* uid, char** shell, int g_getgroup_info(const char* groupname, int* gid); int g_check_user_in_group(const char* username, int gid, int* ok); int g_time1(void); -int g_time2(void); -int g_time3(void); +long long g_time2(void); +long long g_time3(void); int g_save_to_bmp(const char* filename, char* data, int stride_bytes, int width, int height, int depth, int bits_per_pixel); int g_text2bool(const char *s);