[Libreoffice-commits] core.git: sc/source
Markus Mohrhard
markus.mohrhard at googlemail.com
Mon Aug 14 16:11:22 UTC 2017
sc/source/ui/dataprovider/dataprovider.cxx | 42 +++++++++++++++++------------
1 file changed, 25 insertions(+), 17 deletions(-)
New commits:
commit 9f1344d8b53c458fad3ac2b5e9ac4abf7ad64aa3
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Sun Aug 13 00:08:15 2017 +0200
external data: avoid crash due to exception when downloading fails
Change-Id: I96c310cf28c29795b1b211e430d944a9efa5353b
Reviewed-on: https://gerrit.libreoffice.org/41144
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
diff --git a/sc/source/ui/dataprovider/dataprovider.cxx b/sc/source/ui/dataprovider/dataprovider.cxx
index 79b936f5d704..57893197fdc3 100644
--- a/sc/source/ui/dataprovider/dataprovider.cxx
+++ b/sc/source/ui/dataprovider/dataprovider.cxx
@@ -22,29 +22,37 @@ namespace sc {
std::unique_ptr<SvStream> DataProvider::FetchStreamFromURL(const OUString& rURL, OStringBuffer& rBuffer)
{
- uno::Reference< ucb::XSimpleFileAccess3 > xFileAccess( ucb::SimpleFileAccess::create( comphelper::getProcessComponentContext() ), uno::UNO_QUERY );
+ try
+ {
+ uno::Reference< ucb::XSimpleFileAccess3 > xFileAccess( ucb::SimpleFileAccess::create( comphelper::getProcessComponentContext() ), uno::UNO_QUERY );
- uno::Reference< io::XInputStream > xStream;
- xStream = xFileAccess->openFileRead( rURL );
+ uno::Reference< io::XInputStream > xStream;
+ xStream = xFileAccess->openFileRead( rURL );
- const sal_Int32 BUF_LEN = 8000;
- uno::Sequence< sal_Int8 > buffer( BUF_LEN );
+ const sal_Int32 BUF_LEN = 8000;
+ uno::Sequence< sal_Int8 > buffer( BUF_LEN );
- sal_Int32 nRead = 0;
- while ( ( nRead = xStream->readBytes( buffer, BUF_LEN ) ) == BUF_LEN )
- {
- rBuffer.append( reinterpret_cast< const char* >( buffer.getConstArray() ), nRead );
- }
+ sal_Int32 nRead = 0;
+ while ( ( nRead = xStream->readBytes( buffer, BUF_LEN ) ) == BUF_LEN )
+ {
+ rBuffer.append( reinterpret_cast< const char* >( buffer.getConstArray() ), nRead );
+ }
- if ( nRead > 0 )
- {
- rBuffer.append( reinterpret_cast< const char* >( buffer.getConstArray() ), nRead );
- }
+ if ( nRead > 0 )
+ {
+ rBuffer.append( reinterpret_cast< const char* >( buffer.getConstArray() ), nRead );
+ }
- xStream->closeInput();
+ xStream->closeInput();
- SvStream* pStream = new SvMemoryStream(const_cast<char*>(rBuffer.getStr()), rBuffer.getLength(), StreamMode::READ);
- return std::unique_ptr<SvStream>(pStream);
+ SvStream* pStream = new SvMemoryStream(const_cast<char*>(rBuffer.getStr()), rBuffer.getLength(), StreamMode::READ);
+ return std::unique_ptr<SvStream>(pStream);
+ }
+ catch(...)
+ {
+ rBuffer.setLength(0);
+ return nullptr;
+ }
}
ExternalDataSource::ExternalDataSource(const OUString& rURL,
More information about the Libreoffice-commits
mailing list