[Libreoffice-commits] core.git: 2 commits - connectivity/source

Lionel Elie Mamane lionel at mamane.lu
Wed Aug 2 13:50:47 UTC 2017


 connectivity/source/commontools/dbconversion.cxx |   54 ++++++++++++++++-------
 1 file changed, 39 insertions(+), 15 deletions(-)

New commits:
commit 764e7d873f8568ff4981de0139d09401d7f64c02
Author: Lionel Elie Mamane <lionel at mamane.lu>
Date:   Wed Aug 2 15:28:40 2017 +0200

    add a few const purely for documentation reasons
    
    Change-Id: I6b7e5dac24e7aa5d48d6661235059ba29207e1d7

diff --git a/connectivity/source/commontools/dbconversion.cxx b/connectivity/source/commontools/dbconversion.cxx
index d863d299f60c..964b98672eb2 100644
--- a/connectivity/source/commontools/dbconversion.cxx
+++ b/connectivity/source/commontools/dbconversion.cxx
@@ -120,7 +120,7 @@ namespace dbtools
         return  aTemp.makeStringAndClear();
     }
 
-    css::util::Date DBTypeConversion::toDate(sal_Int32 _nVal)
+    css::util::Date DBTypeConversion::toDate(const sal_Int32 _nVal)
     {
         css::util::Date aReturn;
         aReturn.Day = (sal_uInt16)(_nVal % 100);
@@ -130,7 +130,7 @@ namespace dbtools
     }
 
 
-    css::util::Time DBTypeConversion::toTime(sal_Int64 _nVal)
+    css::util::Time DBTypeConversion::toTime(const sal_Int64 _nVal)
     {
         css::util::Time aReturn;
         sal_uInt64 unVal = static_cast<sal_uInt64>(_nVal >= 0 ? _nVal : -_nVal);
@@ -202,7 +202,7 @@ namespace dbtools
         return nDays;
     }
 
-    static void implBuildFromRelative( sal_Int32 nDays, sal_uInt16& rDay, sal_uInt16& rMonth, sal_Int16& rYear)
+    static void implBuildFromRelative( const sal_Int32 nDays, sal_uInt16& rDay, sal_uInt16& rMonth, sal_Int16& rYear)
     {
         sal_Int32   nTempDays;
         sal_Int32   i = 0;
@@ -274,7 +274,7 @@ namespace dbtools
         return ((double)nTime) + toDouble(aTimePart);
     }
 
-    static void addDays(sal_Int32 nDays, css::util::Date& _rDate)
+    static void addDays(const sal_Int32 nDays, css::util::Date& _rDate)
     {
         sal_Int32   nTempDays = implRelativeToAbsoluteNull( _rDate );
 
@@ -291,13 +291,13 @@ namespace dbtools
         {
             _rDate.Day      = 1;
             _rDate.Month    = 1;
-            _rDate.Year     = 00;
+            _rDate.Year     = 1;
         }
         else
             implBuildFromRelative( nTempDays, _rDate.Day, _rDate.Month, _rDate.Year );
     }
 
-    static void subDays( sal_Int32 nDays, css::util::Date& _rDate )
+    static void subDays(const sal_Int32 nDays, css::util::Date& _rDate )
     {
         sal_Int32   nTempDays = implRelativeToAbsoluteNull( _rDate );
 
@@ -314,13 +314,13 @@ namespace dbtools
         {
             _rDate.Day      = 1;
             _rDate.Month    = 1;
-            _rDate.Year     = 00;
+            _rDate.Year     = 1;
         }
         else
             implBuildFromRelative( nTempDays, _rDate.Day, _rDate.Month, _rDate.Year );
     }
 
-    css::util::Date DBTypeConversion::toDate(double dVal, const css::util::Date& _rNullDate)
+    css::util::Date DBTypeConversion::toDate(const double dVal, const css::util::Date& _rNullDate)
     {
         css::util::Date aRet = _rNullDate;
 
@@ -333,9 +333,9 @@ namespace dbtools
         return aRet;
     }
 
-    css::util::Time DBTypeConversion::toTime(double dVal, short nDigits)
+    css::util::Time DBTypeConversion::toTime(const double dVal, short nDigits)
     {
-        sal_Int32 nDays     = (sal_Int32)dVal;
+        const sal_Int32 nDays     = (sal_Int32)dVal;
         sal_Int64 nNS;
         {
             double fSeconds((dVal - (double)nDays) * (fNanoSecondsPerDay / nanoSecInSec));
@@ -381,7 +381,7 @@ namespace dbtools
         return aRet;
     }
 
-    css::util::DateTime DBTypeConversion::toDateTime(double dVal, const css::util::Date& _rNullDate)
+    css::util::DateTime DBTypeConversion::toDateTime(const double dVal, const css::util::Date& _rNullDate)
     {
         css::util::Date aDate = toDate(dVal, _rNullDate);
         // there is not enough precision in a double to have both a date
commit 0ccbd58834259cd7724edacde283f4f0f6ed2db0
Author: Lionel Elie Mamane <lionel at mamane.lu>
Date:   Wed Aug 2 15:27:57 2017 +0200

    tdf#110997 protect calls to implBuildFromRelative from year overflow
    
    Change-Id: I5c6768766673832b7271292af85db1b76e51042c

diff --git a/connectivity/source/commontools/dbconversion.cxx b/connectivity/source/commontools/dbconversion.cxx
index 61abe27d84b8..d863d299f60c 100644
--- a/connectivity/source/commontools/dbconversion.cxx
+++ b/connectivity/source/commontools/dbconversion.cxx
@@ -42,6 +42,16 @@ namespace
     const sal_Int64 hourMask = 10000000000000LL;
 
     const double fNanoSecondsPerDay = nanoSecInSec * secInMin * minInHour * 24.0;
+
+    //  32767-12-31 in "(days since 0001-01-01) + 1" format
+    const sal_Int32 maxDays =  11967896;
+    // -32768-01-01 in "(days since 0001-01-01) + 1" format
+    // Yes, I know it is currently unused. Will have to be used
+    // when we implement negative years. Writing down the correct
+    // value for future reference.
+    // *** Please don't remove just because it is unused ***
+    // Lionel Élie Mamane 2017-08-02
+    // const sal_Int32 minDays = -11968270;
 }
 
 
@@ -269,8 +279,15 @@ namespace dbtools
         sal_Int32   nTempDays = implRelativeToAbsoluteNull( _rDate );
 
         nTempDays += nDays;
-        // TODO: can we remove that check? Would allow dates before 1900.
-        if ( nTempDays <= 0 )
+        if ( nTempDays > maxDays )
+        {
+            _rDate.Day      = 31;
+            _rDate.Month    = 12;
+            _rDate.Year     = 9999;
+        }
+        // TODO: can we replace that check by minDays? Would allow dates BCE
+        //       implBuildFromRelative probably needs to be updated for the "no year 0" question
+        else if ( nTempDays <= 0 )
         {
             _rDate.Day      = 1;
             _rDate.Month    = 1;
@@ -285,8 +302,15 @@ namespace dbtools
         sal_Int32   nTempDays = implRelativeToAbsoluteNull( _rDate );
 
         nTempDays -= nDays;
-        // TODO: can we remove that check? Would allow dates before 1900.
-        if ( nTempDays <= 0 )
+        if ( nTempDays > maxDays )
+        {
+            _rDate.Day      = 31;
+            _rDate.Month    = 12;
+            _rDate.Year     = 9999;
+        }
+        // TODO: can we replace that check by minDays? Would allow dates BCE
+        //       implBuildFromRelative probably needs to be updated for the "no year 0" question
+        else if ( nTempDays <= 0 )
         {
             _rDate.Day      = 1;
             _rDate.Month    = 1;


More information about the Libreoffice-commits mailing list