vcl/workben/mtfdemo.cxx | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-)
New commits: commit d49807bb277f69cfd494f10399e59bd9947a9d29 Author: Hossein <hoss...@libreoffice.org> AuthorDate: Fri Nov 12 10:23:11 2021 +0100 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Fri Nov 12 13:56:07 2021 +0100 Add error handling while creating absolute url * Added error handling while creating absolute url from file name * It was reported as ofz#1493240 Unchecked return value * It has been silenced in 30f1617bd873d9ccf343a280ba27f476d4c7726e and b7c8e4f8ae5402eb665f758f75123e9fe1514d01 Change-Id: Idb8116a5805be38cc37ec1ba28ef226ba160e25b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124214 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/vcl/workben/mtfdemo.cxx b/vcl/workben/mtfdemo.cxx index eb81c3363b16..aae7c092a163 100644 --- a/vcl/workben/mtfdemo.cxx +++ b/vcl/workben/mtfdemo.cxx @@ -13,6 +13,7 @@ #include <com/sun/star/lang/XInitialization.hpp> #include <com/sun/star/registry/XSimpleRegistry.hpp> #include <com/sun/star/ucb/UniversalContentBroker.hpp> +#include <com/sun/star/uno/RuntimeException.hpp> #include <vcl/vclmain.hxx> #include <vcl/layout.hxx> @@ -63,7 +64,7 @@ void DemoMtfWin::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangl } else { - Application::Abort("Can't read metafile"); + Application::Abort("Can't read metafile " + aFileStream.GetFileName()); } aMtf.Play(*GetOutDev(), aMtf.GetActionSize()); @@ -154,8 +155,19 @@ private: OUString sWorkingDir, sFileUrl; osl_getProcessWorkingDir(&sWorkingDir.pData); - (void)osl::FileBase::getFileURLFromSystemPath(aFilename, sFileUrl); - (void)osl::FileBase::getAbsoluteFileURL(sWorkingDir, sFileUrl, maFileName); + osl::FileBase::RC rc = osl::FileBase::getFileURLFromSystemPath(aFilename, sFileUrl); + if (rc == osl::FileBase::E_None) + { + rc = osl::FileBase::getAbsoluteFileURL(sWorkingDir, sFileUrl, maFileName); + if (rc != osl::FileBase::E_None) + { + throw css::uno::RuntimeException("Can not make absolute: " + aFilename); + } + } + else + { + throw css::uno::RuntimeException("Can not get file url from system path: " + aFilename); + } uno::Reference<uno::XComponentContext> xComponentContext = ::cppu::defaultBootstrap_InitialComponentContext(); @@ -169,10 +181,30 @@ private: { GDIMetaFile aMtf; SvFileStream aFileStream(maFileName, StreamMode::READ); - ReadWindowMetafile(aFileStream, aMtf); + + if (aFileStream.IsOpen()) + { + ReadWindowMetafile(aFileStream, aMtf); + } + else + { + throw css::uno::RuntimeException("Can't read metafile " + aFileStream.GetFileName()); + } + OUString sAbsoluteDumpUrl, sDumpUrl; - (void)osl::FileBase::getFileURLFromSystemPath("metadump.xml", sDumpUrl); - (void)osl::FileBase::getAbsoluteFileURL(sWorkingDir, sDumpUrl, sAbsoluteDumpUrl); + rc = osl::FileBase::getFileURLFromSystemPath("metadump.xml", sDumpUrl); + if (rc == osl::FileBase::E_None) + { + rc = osl::FileBase::getAbsoluteFileURL(sWorkingDir, sDumpUrl, sAbsoluteDumpUrl); + if (rc != osl::FileBase::E_None) + { + throw css::uno::RuntimeException("Can not make absolute: metadump.xml"); + } + } + else + { + throw css::uno::RuntimeException("Can not get file url from system path: metadump.xml"); + } aMtf.dumpAsXml(rtl::OUStringToOString(sAbsoluteDumpUrl, RTL_TEXTENCODING_UTF8).getStr()); std::cout << "Dumped metaactions as metadump.xml" << std::endl;