[Libreoffice-commits] core.git: shell/source
Stephan Bergmann (via logerrit)
logerrit at kemper.freedesktop.org
Sat Sep 5 19:20:38 UTC 2020
shell/source/backends/kf5be/kf5access.cxx | 23 ++++++++++++++++-------
1 file changed, 16 insertions(+), 7 deletions(-)
New commits:
commit 1bc728580364c626aa04df624e2afac8fa92890e
Author: Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Sat Sep 5 18:29:59 2020 +0200
Commit: Stephan Bergmann <sbergman at redhat.com>
CommitDate: Sat Sep 5 21:19:56 2020 +0200
Improve QString to OUString conversion
...assuming the way of constructing an OUString from just a QString::utf16
pointer, ignoring QString::size, was not chosen deliberately to cut of the input
string at a potential embedded NUL.
(This change is a prerequisite for making the OUString ctor taking a raw pointer
explicit.)
Change-Id: I3fb3026065f0247c19f0497d28adf422106bd9c4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102083
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman at redhat.com>
diff --git a/shell/source/backends/kf5be/kf5access.cxx b/shell/source/backends/kf5be/kf5access.cxx
index d983b6d308ca..27d047d640d1 100644
--- a/shell/source/backends/kf5be/kf5access.cxx
+++ b/shell/source/backends/kf5be/kf5access.cxx
@@ -45,6 +45,15 @@ namespace
namespace uno = css::uno;
}
+namespace
+{
+OUString fromQStringToOUString(QString const& s)
+{
+ // Conversion from QString size()'s int to OUString's sal_Int32 should be non-narrowing:
+ return { reinterpret_cast<char16_t const*>(s.utf16()), s.size() };
+}
+}
+
css::beans::Optional<css::uno::Any> getValue(OUString const& id)
{
if (id == "ExternalMailer")
@@ -58,7 +67,7 @@ css::beans::Optional<css::uno::Any> getValue(OUString const& id)
aClientProgram = QStringLiteral("kmail");
else
aClientProgram = aClientProgram.section(QLatin1Char(' '), 0, 0);
- sClientProgram = reinterpret_cast<const sal_Unicode*>(aClientProgram.utf16());
+ sClientProgram = fromQStringToOUString(aClientProgram);
return css::beans::Optional<css::uno::Any>(true, uno::makeAny(sClientProgram));
}
else if (id == "SourceViewFontHeight")
@@ -71,7 +80,7 @@ css::beans::Optional<css::uno::Any> getValue(OUString const& id)
{
const QFont aFixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont);
const QString aFontName = aFixedFont.family();
- const OUString sFontName = reinterpret_cast<const sal_Unicode*>(aFontName.utf16());
+ const OUString sFontName = fromQStringToOUString(aFontName);
return css::beans::Optional<css::uno::Any>(true, uno::makeAny(sFontName));
}
else if (id == "EnableATToolSupport")
@@ -90,7 +99,7 @@ css::beans::Optional<css::uno::Any> getValue(OUString const& id)
OUString sDocumentsURL;
if (aDocumentsDir.endsWith(QLatin1Char('/')))
aDocumentsDir.truncate(aDocumentsDir.length() - 1);
- sDocumentsDir = reinterpret_cast<const sal_Unicode*>(aDocumentsDir.utf16());
+ sDocumentsDir = fromQStringToOUString(aDocumentsDir);
osl_getFileURLFromSystemPath(sDocumentsDir.pData, &sDocumentsURL.pData);
return css::beans::Optional<css::uno::Any>(true, uno::makeAny(sDocumentsURL));
}
@@ -117,7 +126,7 @@ css::beans::Optional<css::uno::Any> getValue(OUString const& id)
if (!aFTPProxy.isEmpty())
{
QUrl aProxy(aFTPProxy);
- OUString sProxy = reinterpret_cast<const sal_Unicode*>(aProxy.host().utf16());
+ OUString sProxy = fromQStringToOUString(aProxy.host());
return css::beans::Optional<css::uno::Any>(true, uno::makeAny(sProxy));
}
}
@@ -171,7 +180,7 @@ css::beans::Optional<css::uno::Any> getValue(OUString const& id)
if (!aHTTPProxy.isEmpty())
{
QUrl aProxy(aHTTPProxy);
- OUString sProxy = reinterpret_cast<const sal_Unicode*>(aProxy.host().utf16());
+ OUString sProxy = fromQStringToOUString(aProxy.host());
return css::beans::Optional<css::uno::Any>(true, uno::makeAny(sProxy));
}
}
@@ -225,7 +234,7 @@ css::beans::Optional<css::uno::Any> getValue(OUString const& id)
if (!aHTTPSProxy.isEmpty())
{
QUrl aProxy(aHTTPSProxy);
- OUString sProxy = reinterpret_cast<const sal_Unicode*>(aProxy.host().utf16());
+ OUString sProxy = fromQStringToOUString(aProxy.host());
return css::beans::Optional<css::uno::Any>(true, uno::makeAny(sProxy));
}
}
@@ -275,7 +284,7 @@ css::beans::Optional<css::uno::Any> getValue(OUString const& id)
OUString sNoProxyFor;
aNoProxyFor = aNoProxyFor.replace(QLatin1Char(','), QLatin1Char(';'));
- sNoProxyFor = reinterpret_cast<const sal_Unicode*>(aNoProxyFor.utf16());
+ sNoProxyFor = fromQStringToOUString(aNoProxyFor);
return css::beans::Optional<css::uno::Any>(true, uno::makeAny(sNoProxyFor));
}
}
More information about the Libreoffice-commits
mailing list