[Libreoffice-commits] core.git: 2 commits - desktop/source vcl/source
Michael Meeks (via logerrit)
logerrit at kemper.freedesktop.org
Mon Nov 4 16:44:13 UTC 2019
desktop/source/lib/init.cxx | 85 ++++++++++++-------------------------------
vcl/source/window/window.cxx | 2 -
2 files changed, 25 insertions(+), 62 deletions(-)
New commits:
commit 5dff78b49f489aaa552384e14225a798a8a093a6
Author: Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Mon Nov 4 15:44:04 2019 +0000
Commit: Michael Meeks <michael.meeks at collabora.com>
CommitDate: Mon Nov 4 17:43:20 2019 +0100
lok: share conversion of OUString to C strings.
Change-Id: I0178f673dc1e59d9fba8f3daae532f19b46e4d36
Reviewed-on: https://gerrit.libreoffice.org/82036
Tested-by: Jenkins
Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index b00638eaa127..ef201b32061e 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -260,6 +260,20 @@ static OUString getUString(const char* pString)
return OStringToOUString(sString, RTL_TEXTENCODING_UTF8);
}
+// Tolerate embedded \0s etc.
+static char *convertOString(const OString &rStr)
+{
+ char* pMemory = static_cast<char*>(malloc(rStr.getLength() + 1));
+ assert(pMemory); // don't tolerate failed allocations.
+ memcpy(pMemory, rStr.getStr(), rStr.getLength() + 1);
+ return pMemory;
+}
+
+static char *convertOUString(const OUString &aStr)
+{
+ return convertOString(OUStringToOString(aStr, RTL_TEXTENCODING_UTF8));
+}
+
/// Try to convert a relative URL to an absolute one, unless it already looks like a URL.
static OUString getAbsoluteURL(const char* pURL)
{
@@ -2544,13 +2558,7 @@ static char* doc_getPartInfo(LibreOfficeKitDocument* pThis, int nPart)
return nullptr;
}
- OUString aPartInfo = pDoc->getPartInfo( nPart );
- OString aString = OUStringToOString(aPartInfo, RTL_TEXTENCODING_UTF8);
-
- char* pMemory = static_cast<char*>(malloc(aString.getLength() + 1));
- assert(pMemory); // Don't handle OOM conditions
- strcpy(pMemory, aString.getStr());
- return pMemory;
+ return convertOUString(pDoc->getPartInfo(nPart));
}
static void doc_selectPart(LibreOfficeKitDocument* pThis, int nPart, int nSelect)
@@ -2599,13 +2607,7 @@ static char* doc_getPartPageRectangles(LibreOfficeKitDocument* pThis)
return nullptr;
}
- OUString sRectangles = pDoc->getPartPageRectangles();
- OString aString = OUStringToOString(sRectangles, RTL_TEXTENCODING_UTF8);
- char* pMemory = static_cast<char*>(malloc(aString.getLength() + 1));
- assert(pMemory); // Don't handle OOM conditions
- strcpy(pMemory, aString.getStr());
- return pMemory;
-
+ return convertOUString(pDoc->getPartPageRectangles());
}
static char* doc_getPartName(LibreOfficeKitDocument* pThis, int nPart)
@@ -2622,13 +2624,7 @@ static char* doc_getPartName(LibreOfficeKitDocument* pThis, int nPart)
return nullptr;
}
- OUString sName = pDoc->getPartName( nPart );
- OString aString = OUStringToOString(sName, RTL_TEXTENCODING_UTF8);
- char* pMemory = static_cast<char*>(malloc(aString.getLength() + 1));
- assert(pMemory); // Don't handle OOM conditions
- strcpy(pMemory, aString.getStr());
- return pMemory;
-
+ return convertOUString(pDoc->getPartName(nPart));
}
static char* doc_getPartHash(LibreOfficeKitDocument* pThis, int nPart)
@@ -2645,13 +2641,7 @@ static char* doc_getPartHash(LibreOfficeKitDocument* pThis, int nPart)
return nullptr;
}
- OUString sHash = pDoc->getPartHash(nPart);
- OString aString = OUStringToOString(sHash, RTL_TEXTENCODING_UTF8);
- char* pMemory = static_cast<char*>(malloc(aString.getLength() + 1));
- assert(pMemory); // Don't handle OOM conditions
- strcpy(pMemory, aString.getStr());
- return pMemory;
-
+ return convertOUString(pDoc->getPartHash(nPart));
}
static void doc_setPartMode(LibreOfficeKitDocument* pThis,
@@ -3752,14 +3742,6 @@ static bool getFromTransferrable(
return true;
}
-// Tolerate embedded \0s etc.
-static char *convertOString(const OString &rStr)
-{
- char* pMemory = static_cast<char*>(malloc(rStr.getLength() + 1));
- memcpy(pMemory, rStr.getStr(), rStr.getLength() + 1);
- return pMemory;
-}
-
static char* doc_getTextSelection(LibreOfficeKitDocument* pThis, const char* pMimeType, char** pUsedMimeType)
{
comphelper::ProfileZone aZone("doc_getTextSelection");
@@ -3914,7 +3896,7 @@ static int doc_getClipboard(LibreOfficeKitDocument* pThis,
else
{
(*pOutSizes)[i] = aRet.getLength();
- (*pOutStreams)[i] = convertOString(aRet);
+ (*pOutStreams)[i] = convertOString(aRet);
}
}
@@ -4490,13 +4472,8 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo
OUString aHeaders = pDoc->getRowColumnHeaders(aRectangle);
if (aHeaders.isEmpty())
return nullptr;
-
- OString aString = OUStringToOString(aHeaders, RTL_TEXTENCODING_UTF8);
-
- char* pMemory = static_cast<char*>(malloc(aString.getLength() + 1));
- assert(pMemory); // Don't handle OOM conditions
- strcpy(pMemory, aString.getStr());
- return pMemory;
+ else
+ return convertOUString(aHeaders);
}
else if (aCommand.startsWith(aCellCursor))
{
@@ -4543,12 +4520,7 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo
while (nParamIndex >= 0);
}
- OString aString = pDoc->getCellCursor(nOutputWidth, nOutputHeight, nTileWidth, nTileHeight);
-
- char* pMemory = static_cast<char*>(malloc(aString.getLength() + 1));
- assert(pMemory); // Don't handle OOM conditions
- strcpy(pMemory, aString.getStr());
- return pMemory;
+ return convertOString(pDoc->getCellCursor(nOutputWidth, nOutputHeight, nTileWidth, nTileHeight));
}
else if (aCommand.startsWith(aFontSubset))
{
@@ -5110,11 +5082,7 @@ static char* lo_getError (LibreOfficeKit *pThis)
SolarMutexGuard aGuard;
LibLibreOffice_Impl* pLib = static_cast<LibLibreOffice_Impl*>(pThis);
- OString aString = OUStringToOString(pLib->maLastExceptionMsg, RTL_TEXTENCODING_UTF8);
- char* pMemory = static_cast<char*>(malloc(aString.getLength() + 1));
- assert(pMemory); // Don't handle OOM conditions
- strcpy(pMemory, aString.getStr());
- return pMemory;
+ return convertOUString(pLib->maLastExceptionMsg);
}
static void lo_freeError(char* pFree)
@@ -5206,12 +5174,7 @@ static char* lo_getVersionInfo(SAL_UNUSED_PARAMETER LibreOfficeKit* /*pThis*/)
"\"BuildId\": \"%BUILDID\" "
"}"
);
- const OString sVersionStr = OUStringToOString(ReplaceStringHookProc(sVersionStrTemplate), RTL_TEXTENCODING_UTF8);
-
- char* pVersion = static_cast<char*>(malloc(sVersionStr.getLength() + 1));
- assert(pVersion); // Don't handle OOM conditions
- strcpy(pVersion, sVersionStr.getStr());
- return pVersion;
+ return convertOUString(ReplaceStringHookProc(sVersionStrTemplate));
}
static void force_c_locale()
commit ae1052613be96be1ec37695b094906edb41ac8cf
Author: Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Mon Nov 4 15:42:07 2019 +0000
Commit: Michael Meeks <michael.meeks at collabora.com>
CommitDate: Mon Nov 4 17:43:13 2019 +0100
lok: avoid ILibreOfficeKitNotifier null ptr de-reference on shutdown.
Change-Id: I79c8fa3ebf7ed457b7bebb4da536eb83f5cac567
Reviewed-on: https://gerrit.libreoffice.org/82035
Tested-by: Jenkins
Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx
index b3df086f64be..0072ec49f1b8 100644
--- a/vcl/source/window/window.cxx
+++ b/vcl/source/window/window.cxx
@@ -3227,7 +3227,7 @@ ILibreOfficeKitNotifier::~ILibreOfficeKitNotifier()
for (auto it = GetLOKWindowsMap().begin(); it != GetLOKWindowsMap().end();)
{
WindowImpl* pWindowImpl = it->second->ImplGetWindowImpl();
- if (pWindowImpl->mpLOKNotifier == this)
+ if (pWindowImpl && pWindowImpl->mpLOKNotifier == this)
{
pWindowImpl->mpLOKNotifier = nullptr;
pWindowImpl->mnLOKWindowId = 0;
More information about the Libreoffice-commits
mailing list