common: g_time[23]() should be long long

signed int causes overflow since it returns epoch time in msec.
This commit is contained in:
Koichiro IWAO 2018-04-03 16:52:12 +09:00
parent ab317cc5ed
commit 5f845f7519
No known key found for this signature in database
GPG Key ID: 9F72CDBC01BF10EB
2 changed files with 7 additions and 7 deletions

View File

@ -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
}

View File

@ -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);