summaryrefslogtreecommitdiff
path: root/tools/source
diff options
context:
space:
mode:
authorUrja Rannikko <urjaman@gmail.com>2021-12-05 14:29:09 +0200
committerJan-Marek Glogowski <glogow@fbihome.de>2021-12-06 19:34:13 +0100
commit18407807085e47f56ec972c2e1ce6db9a2375e21 (patch)
treef9b304f16ecbdcdef3a7a92acaeff9b3bd97ba78 /tools/source
parentc49f269fbe3bd069571497973ce8c1b9f856a8af (diff)
tdf#128715 fix tools::Time::GetMonotonicTicks() on 32-bit linux
Since time_t and thus tv_sec is (still, for now) 32-bit on these architechtures, the multiplication of seconds to microseconds happened in 32-bit thus causing a rollover roughly every 4295 seconds. Fix by casting tv_sec to sal_uInt64 before the multiplication. Also fixes tdf#144975. Change-Id: I829d3406208545a816979cb58daaeb99ec2d5294 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126379 Tested-by: Jenkins Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de> (cherry picked from commit 7fa9b09bc271d91792fe78c5cb03430bf38155a8) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126305
Diffstat (limited to 'tools/source')
-rw-r--r--tools/source/datetime/ttime.cxx5
1 files changed, 3 insertions, 2 deletions
diff --git a/tools/source/datetime/ttime.cxx b/tools/source/datetime/ttime.cxx
index c6c89c934886..ee9e427205ef 100644
--- a/tools/source/datetime/ttime.cxx
+++ b/tools/source/datetime/ttime.cxx
@@ -477,11 +477,12 @@ sal_uInt64 tools::Time::GetMonotonicTicks()
#if defined(_POSIX_TIMERS)
struct timespec currentTime;
clock_gettime( CLOCK_MONOTONIC, &currentTime );
- nMicroSeconds = currentTime.tv_sec * 1000 * 1000 + currentTime.tv_nsec / 1000;
+ nMicroSeconds
+ = static_cast<sal_uInt64>(currentTime.tv_sec) * 1000 * 1000 + currentTime.tv_nsec / 1000;
#else
struct timeval currentTime;
gettimeofday( &currentTime, nullptr );
- nMicroSeconds = currentTime.tv_sec * 1000 * 1000 + currentTime.tv_usec;
+ nMicroSeconds = static_cast<sal_uInt64>(currentTime.tv_sec) * 1000 * 1000 + currentTime.tv_usec;
#endif
#endif // __MACH__
return nMicroSeconds;