diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-08-29 12:15:54 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-08-30 09:40:36 +0200 |
commit | 5ff20b1c726509ad88058c953406a2bd0c8e194b (patch) | |
tree | 336d5799d2933b093e08e09e8e5b53f68d14ff12 /forms | |
parent | 59bcc90cad1bf07e6841dbd01ef503c10032ff0b (diff) |
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@collabora.co.uk>
Diffstat (limited to 'forms')
-rw-r--r-- | forms/source/xforms/xpathlib/xpathlib.cxx | 29 |
1 files changed, 10 insertions, 19 deletions
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; } |