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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Thu Aug 30 07:41:02 UTC 2018


 forms/source/xforms/xpathlib/xpathlib.cxx |   29 ++++++++++-------------------
 1 file changed, 10 insertions(+), 19 deletions(-)

New commits:
commit 5ff20b1c726509ad88058c953406a2bd0c8e194b
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Wed Aug 29 12:15:54 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Aug 30 09:40:36 2018 +0200

    no need to allocate a new string in parseDuration
    
    just parse the incoming string in-place with boost::lexical_cast
    
    Change-Id: Ie165a80ea3cd10ca883afdff1ad1289edda3e9ab
    Reviewed-on: https://gerrit.libreoffice.org/59770
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/forms/source/xforms/xpathlib/xpathlib.cxx b/forms/source/xforms/xpathlib/xpathlib.cxx
index 177251bb1709..9ff6426ec456 100644
--- a/forms/source/xforms/xpathlib/xpathlib.cxx
+++ b/forms/source/xforms/xpathlib/xpathlib.cxx
@@ -36,8 +36,9 @@
 #include <com/sun/star/xml/dom/XDocument.hpp>
 #include <com/sun/star/lang/XUnoTunnel.hpp>
 
-#include "xpathlib.hxx"
+#include <boost/lexical_cast.hpp>
 
+#include "xpathlib.hxx"
 #include "extension.hxx"
 
 // C interface
@@ -373,10 +374,7 @@ static bool parseDuration(const xmlChar* aString, bool& bNegative, sal_Int32& nY
                               sal_Int32& nHours, sal_Int32& nMinutes, sal_Int32& nSeconds)
 {
     bool bTime = false; // in part after T
-    sal_Int32 nLength = strlen(reinterpret_cast<char const *>(aString))+1;
-    char *pString = static_cast<char*>(std::malloc(nLength));
-    char *pString0 = pString;
-    strncpy(pString, reinterpret_cast<char const *>(aString), nLength);
+    const xmlChar *pString = aString;
 
     if (pString[0] == '-') {
         bNegative = true;
@@ -385,41 +383,35 @@ static bool parseDuration(const xmlChar* aString, bool& bNegative, sal_Int32& nY
 
     if (pString[0] != 'P')
     {
-        std::free(pString0);
         return false;
     }
 
     pString++;
-    char* pToken = pString;
+    const xmlChar* pToken = pString;
     while(pToken[0] != 0)
     {
         switch(pToken[0]) {
         case 'Y':
-            pToken[0] = 0;
-            nYears = atoi(pString);
+            nYears = boost::lexical_cast<sal_Int32>(pString, pString-pToken);
             pString = ++pToken;
             break;
         case 'M':
-            pToken[0] = 0;
             if (!bTime)
-                nMonth = atoi(pString);
+                nMonth = boost::lexical_cast<sal_Int32>(pString, pString-pToken);
             else
-                nMinutes = atoi(pString);
+                nMinutes = boost::lexical_cast<sal_Int32>(pString, pString-pToken);
             pString = ++pToken;
             break;
         case 'D':
-            pToken[0] = 0;
-            nDays = atoi(pString);
+            nDays = boost::lexical_cast<sal_Int32>(pString, pString-pToken);
             pString = ++pToken;
             break;
         case 'H':
-            pToken[0] = 0;
-            nHours = atoi(pString);
+            nHours = boost::lexical_cast<sal_Int32>(pString, pString-pToken);
             pString = ++pToken;
             break;
         case 'S':
-            pToken[0] = 0;
-            nSeconds = atoi(pString);
+            nSeconds = boost::lexical_cast<sal_Int32>(pString, pString-pToken);
             pString = ++pToken;
             break;
         case 'T':
@@ -430,7 +422,6 @@ static bool parseDuration(const xmlChar* aString, bool& bNegative, sal_Int32& nY
             pToken++;
         }
     }
-    std::free(pString0);
     return true;
 }
 


More information about the Libreoffice-commits mailing list