[Libreoffice-commits] core.git: basic/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Nov 13 20:51:49 UTC 2018


 basic/source/runtime/methods.cxx |   83 +++++++++++++++++++++++++--------------
 1 file changed, 55 insertions(+), 28 deletions(-)

New commits:
commit 9950e50a0f304362f569d4dc0bd9ca30b7b6291d
Author:     Eike Rathke <erack at redhat.com>
AuthorDate: Tue Nov 13 15:04:02 2018 +0100
Commit:     Eike Rathke <erack at redhat.com>
CommitDate: Tue Nov 13 21:51:25 2018 +0100

    Set error also in non-UNO/UCB case file date failures, tdf#121337 follow-up
    
    And do not attempt to format an odd date in case of failure.
    
    Change-Id: I82e93f9e473f42735b6a7e7b634b14ee7f09941d
    Reviewed-on: https://gerrit.libreoffice.org/63331
    Reviewed-by: Eike Rathke <erack at redhat.com>
    Tested-by: Jenkins

diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx
index b2f639e1a6c4..84202c8d4e45 100644
--- a/basic/source/runtime/methods.cxx
+++ b/basic/source/runtime/methods.cxx
@@ -3035,43 +3035,70 @@ void SbRtl_FileDateTime(StarBASIC *, SbxArray & rPar, bool)
         }
         else
         {
-            DirectoryItem aItem;
-            DirectoryItem::get( getFullPath( aPath ), aItem );
-            FileStatus aFileStatus( osl_FileStatus_Mask_ModifyTime );
-            aItem.getFileStatus( aFileStatus );
-            TimeValue aTimeVal = aFileStatus.getModifyTime();
-            oslDateTime aDT;
-            osl_getDateTimeFromTimeValue( &aTimeVal, &aDT );
+            bool bSuccess = false;
+            do
+            {
+                DirectoryItem aItem;
+                if (DirectoryItem::get( getFullPath( aPath ), aItem ) != FileBase::E_None)
+                    break;
 
-            aTime = tools::Time( aDT.Hours, aDT.Minutes, aDT.Seconds, aDT.NanoSeconds );
-            aDate = Date( aDT.Day, aDT.Month, aDT.Year );
-        }
+                FileStatus aFileStatus( osl_FileStatus_Mask_ModifyTime );
+                if (aItem.getFileStatus( aFileStatus ) != FileBase::E_None)
+                    break;
 
-        double fSerial = aDate.IsEmpty() ? 0 : static_cast<double>(GetDayDiff( aDate ));
-        long nSeconds = aTime.GetHour();
-        nSeconds *= 3600;
-        nSeconds += aTime.GetMin() * 60;
-        nSeconds += aTime.GetSec();
-        double nDays = static_cast<double>(nSeconds) / (24.0*3600.0);
-        fSerial += nDays;
+                TimeValue aTimeVal = aFileStatus.getModifyTime();
+                oslDateTime aDT;
+                if (!osl_getDateTimeFromTimeValue( &aTimeVal, &aDT ))
+                    // Strictly spoken this is not an i/o error but some other failure.
+                    break;
 
-        Color* pCol;
+                aTime = tools::Time( aDT.Hours, aDT.Minutes, aDT.Seconds, aDT.NanoSeconds );
+                aDate = Date( aDT.Day, aDT.Month, aDT.Year );
+                bSuccess = true;
+            }
+            while(false);
 
-        std::shared_ptr<SvNumberFormatter> pFormatter;
-        sal_uInt32 nIndex;
-        if( GetSbData()->pInst )
+            if (!bSuccess)
+                StarBASIC::Error( ERRCODE_IO_GENERAL );
+        }
+
+        // An empty date shall not result in a formatted null-date (1899-12-30
+        // or 1900-01-01) or even worse -0001-12-03 or some such due to how
+        // GetDayDiff() treats things. There should be an error set in this
+        // case anyway because of a missing file or other error above, but.. so
+        // do not even bother to use the number formatter.
+        OUString aRes;
+        if (aDate.IsEmpty())
         {
-            pFormatter = GetSbData()->pInst->GetNumberFormatter();
-            nIndex = GetSbData()->pInst->GetStdDateTimeIdx();
+            aRes = "0000-00-00 00:00:00";
         }
         else
         {
-            sal_uInt32 n;
-            pFormatter = SbiInstance::PrepareNumberFormatter( n, n, nIndex );
-        }
+            double fSerial = static_cast<double>(GetDayDiff( aDate ));
+            long nSeconds = aTime.GetHour();
+            nSeconds *= 3600;
+            nSeconds += aTime.GetMin() * 60;
+            nSeconds += aTime.GetSec();
+            double nDays = static_cast<double>(nSeconds) / (24.0*3600.0);
+            fSerial += nDays;
 
-        OUString aRes;
-        pFormatter->GetOutputString( fSerial, nIndex, aRes, &pCol );
+            Color* pCol;
+
+            std::shared_ptr<SvNumberFormatter> pFormatter;
+            sal_uInt32 nIndex;
+            if( GetSbData()->pInst )
+            {
+                pFormatter = GetSbData()->pInst->GetNumberFormatter();
+                nIndex = GetSbData()->pInst->GetStdDateTimeIdx();
+            }
+            else
+            {
+                sal_uInt32 n;
+                pFormatter = SbiInstance::PrepareNumberFormatter( n, n, nIndex );
+            }
+
+            pFormatter->GetOutputString( fSerial, nIndex, aRes, &pCol );
+        }
         rPar.Get(0)->PutString( aRes );
     }
 }


More information about the Libreoffice-commits mailing list