From 7e5f69aa33509a359b547b9a4a6569a55cd5d5c9 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Sun, 20 Oct 2024 22:51:02 +0500 Subject: Make tools::Time ctor taking sal_Int64 private This ctor is meant to set the value of nTime directly; and that value is not nanoseconds, but an encoded value, using SEC_/MIN_/HOUR_MASK. But in some places, this ctor was misused for setting of nanoseconds, which would only accidentally work for values less than one second. All places that initialized tools::Time with 0, now use EMPTY. This makes the ctor private; and for the very few cases where really the encoded value of nTime is stored / restored, fromEncodedTime is introduced. Change-Id: I1f1994bd9aab1b51a41b1de637619049fe820da4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175283 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- editeng/source/misc/svxacorr.cxx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'editeng/source/misc') diff --git a/editeng/source/misc/svxacorr.cxx b/editeng/source/misc/svxacorr.cxx index 055d46879aa6..0c3540051e49 100644 --- a/editeng/source/misc/svxacorr.cxx +++ b/editeng/source/misc/svxacorr.cxx @@ -1891,12 +1891,17 @@ bool SvxAutoCorrect::CreateLanguageFile( const LanguageTag& rLanguageTag, bool b SvxAutoCorrectLanguageLists* pLists = nullptr; - tools::Time nMinTime( 0, 2 ), nAktTime( tools::Time::SYSTEM ), nLastCheckTime( tools::Time::EMPTY ); + tools::Time nAktTime(tools::Time::SYSTEM); auto nFndPos = aLastFileTable.find(rLanguageTag); - if(nFndPos != aLastFileTable.end() && - (nLastCheckTime.SetTime(nFndPos->second), nLastCheckTime < nAktTime) && - nAktTime - nLastCheckTime < nMinTime) + bool lastCheckLessThan2MinutesAgo = nFndPos != aLastFileTable.end(); + if (lastCheckLessThan2MinutesAgo) + { + const tools::Time nLastCheckTime(tools::Time::fromEncodedTime(nFndPos->second)); + lastCheckLessThan2MinutesAgo + = nLastCheckTime < nAktTime && nAktTime - nLastCheckTime < tools::Time(0, 2); + } + if (lastCheckLessThan2MinutesAgo) { // no need to test the file, because the last check is not older then // 2 minutes. -- cgit