summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2014-02-24 10:01:55 +0000
committerCaolán McNamara <caolanm@redhat.com>2014-02-24 12:53:09 +0000
commite72f739393643a566bc61b9c45474fbab99c4daf (patch)
tree1b7628d40bda19b826db634de3613745ec8a6fdb
parent662283db76783be9cf44a16aa2b1d7b475088c83 (diff)
coverity#707318 Uncaught exception
Change-Id: I65bfcbe4ab6fceed3ae474dcb3225df197ddaa2b
-rw-r--r--sw/source/ui/uno/swdetect.cxx275
1 files changed, 139 insertions, 136 deletions
diff --git a/sw/source/ui/uno/swdetect.cxx b/sw/source/ui/uno/swdetect.cxx
index ef54f79fc9ac..35bcd8fb322c 100644
--- a/sw/source/ui/uno/swdetect.cxx
+++ b/sw/source/ui/uno/swdetect.cxx
@@ -175,173 +175,176 @@ OUString SAL_CALL SwFilterDetect::detect( Sequence< PropertyValue >& lDescriptor
}
else
{
- // ctor of SfxMedium uses owner transition of ItemSet
- SfxMedium aMedium( aURL, bWasReadOnly ? STREAM_STD_READ : STREAM_STD_READWRITE, NULL, pSet );
- aMedium.UseInteractionHandler( sal_True );
- if ( aMedium.GetErrorCode() == ERRCODE_NONE )
+ try
{
- // remember input stream and content and put them into the descriptor later
- // should be done here since later the medium can switch to a version
- xStream = aMedium.GetInputStream();
- xContent = aMedium.GetContent();
- bReadOnly = aMedium.IsReadOnly();
-
- sal_Bool bIsStorage = aMedium.IsStorage();
- if ( bIsStorage )
+ // ctor of SfxMedium uses owner transition of ItemSet
+ SfxMedium aMedium( aURL, bWasReadOnly ? STREAM_STD_READ : STREAM_STD_READWRITE, NULL, pSet );
+ aMedium.UseInteractionHandler( sal_True );
+ if ( aMedium.GetErrorCode() == ERRCODE_NONE )
{
- Reference< embed::XStorage > xStorage = aMedium.GetStorage( sal_False );
- if ( aMedium.GetLastStorageCreationState() != ERRCODE_NONE )
+ // remember input stream and content and put them into the descriptor later
+ // should be done here since later the medium can switch to a version
+ xStream = aMedium.GetInputStream();
+ xContent = aMedium.GetContent();
+ bReadOnly = aMedium.IsReadOnly();
+
+ sal_Bool bIsStorage = aMedium.IsStorage();
+ if ( bIsStorage )
{
- // error during storage creation means _here_ that the medium
- // is broken, but we can not handle it in medium since impossibility
- // to create a storage does not _always_ means that the medium is broken
- aMedium.SetError( aMedium.GetLastStorageCreationState(), OUString( OSL_LOG_PREFIX ) );
- if ( xInteraction.is() )
+ Reference< embed::XStorage > xStorage = aMedium.GetStorage( sal_False );
+ if ( aMedium.GetLastStorageCreationState() != ERRCODE_NONE )
{
- OUString empty;
- try
- {
- InteractiveAppException xException( empty,
- Reference< XInterface >(),
- InteractionClassification_ERROR,
- aMedium.GetError() );
-
- Reference< XInteractionRequest > xRequest(
- new ucbhelper::SimpleInteractionRequest( makeAny( xException ),
- ucbhelper::CONTINUATION_APPROVE ) );
- xInteraction->handle( xRequest );
- }
- catch (const Exception&)
+ // error during storage creation means _here_ that the medium
+ // is broken, but we can not handle it in medium since impossibility
+ // to create a storage does not _always_ means that the medium is broken
+ aMedium.SetError( aMedium.GetLastStorageCreationState(), OUString( OSL_LOG_PREFIX ) );
+ if ( xInteraction.is() )
{
+ OUString empty;
+ try
+ {
+ InteractiveAppException xException( empty,
+ Reference< XInterface >(),
+ InteractionClassification_ERROR,
+ aMedium.GetError() );
+
+ Reference< XInteractionRequest > xRequest(
+ new ucbhelper::SimpleInteractionRequest( makeAny( xException ),
+ ucbhelper::CONTINUATION_APPROVE ) );
+ xInteraction->handle( xRequest );
+ }
+ catch (const Exception&)
+ {
+ }
}
}
- }
- else
- {
- OSL_ENSURE( xStorage.is(), "At this point storage must exist!" );
-
- try
+ else
{
- const SfxFilter* pPreFilter = !aPreselectedFilterName.isEmpty() ?
- SfxFilterMatcher().GetFilter4FilterName( aPreselectedFilterName ) : !aTypeName.isEmpty() ?
- SfxFilterMatcher(OUString("swriter")).GetFilter4EA( aTypeName ) : 0;
- if (!pPreFilter)
- pPreFilter = SfxFilterMatcher(OUString("sweb")).GetFilter4EA( aTypeName );
- OUString aFilterName;
- if ( pPreFilter )
+ OSL_ENSURE( xStorage.is(), "At this point storage must exist!" );
+
+ try
{
- aFilterName = pPreFilter->GetName();
- aTypeName = pPreFilter->GetTypeName();
- }
+ const SfxFilter* pPreFilter = !aPreselectedFilterName.isEmpty() ?
+ SfxFilterMatcher().GetFilter4FilterName( aPreselectedFilterName ) : !aTypeName.isEmpty() ?
+ SfxFilterMatcher(OUString("swriter")).GetFilter4EA( aTypeName ) : 0;
+ if (!pPreFilter)
+ pPreFilter = SfxFilterMatcher(OUString("sweb")).GetFilter4EA( aTypeName );
+ OUString aFilterName;
+ if ( pPreFilter )
+ {
+ aFilterName = pPreFilter->GetName();
+ aTypeName = pPreFilter->GetTypeName();
+ }
- aTypeName = SfxFilter::GetTypeFromStorage( xStorage, pPreFilter ? pPreFilter->IsOwnTemplateFormat() : sal_False, &aFilterName );
- }
- catch (const WrappedTargetException& aWrap)
- {
- if (!bDeepDetection)
- // Bail out early unless it's a deep detection.
- return OUString();
+ aTypeName = SfxFilter::GetTypeFromStorage( xStorage, pPreFilter ? pPreFilter->IsOwnTemplateFormat() : sal_False, &aFilterName );
+ }
+ catch (const WrappedTargetException& aWrap)
+ {
+ if (!bDeepDetection)
+ // Bail out early unless it's a deep detection.
+ return OUString();
- packages::zip::ZipIOException aZipException;
+ packages::zip::ZipIOException aZipException;
- // repairing is done only if this type is requested from outside
- // we don't do any type detection on broken packages (f.e. because it might be impossible), so any requested
- // type will be accepted if the user allows to repair the file
- if ( ( aWrap.TargetException >>= aZipException ) && ( !aTypeName.isEmpty() || !aPreselectedFilterName.isEmpty() ) )
- {
- if ( xInteraction.is() )
+ // repairing is done only if this type is requested from outside
+ // we don't do any type detection on broken packages (f.e. because it might be impossible), so any requested
+ // type will be accepted if the user allows to repair the file
+ if ( ( aWrap.TargetException >>= aZipException ) && ( !aTypeName.isEmpty() || !aPreselectedFilterName.isEmpty() ) )
{
- // the package is a broken one
- aDocumentTitle = aMedium.GetURLObject().getName(
- INetURLObject::LAST_SEGMENT,
- true,
- INetURLObject::DECODE_WITH_CHARSET );
-
- if ( !bRepairPackage )
+ if ( xInteraction.is() )
{
- // ask the user whether he wants to try to repair
- RequestPackageReparation aRequest( aDocumentTitle );
- xInteraction->handle( aRequest.GetRequest() );
- bRepairAllowed = aRequest.isApproved();
+ // the package is a broken one
+ aDocumentTitle = aMedium.GetURLObject().getName(
+ INetURLObject::LAST_SEGMENT,
+ true,
+ INetURLObject::DECODE_WITH_CHARSET );
+
+ if ( !bRepairPackage )
+ {
+ // ask the user whether he wants to try to repair
+ RequestPackageReparation aRequest( aDocumentTitle );
+ xInteraction->handle( aRequest.GetRequest() );
+ bRepairAllowed = aRequest.isApproved();
+ }
+
+ if ( !bRepairAllowed )
+ {
+ // repair either not allowed or not successful
+ // repair either not allowed or not successful
+ NotifyBrokenPackage aNotifyRequest( aDocumentTitle );
+ xInteraction->handle( aNotifyRequest.GetRequest() );
+
+ Reference< ::comphelper::OIHWrapNoFilterDialog > xHandler = new ::comphelper::OIHWrapNoFilterDialog( xInteraction );
+ if ( nIndexOfInteractionHandler != -1 )
+ lDescriptor[nIndexOfInteractionHandler].Value <<= Reference< XInteractionHandler >( static_cast< XInteractionHandler* >( xHandler.get() ) );
+
+ aMedium.SetError( ERRCODE_ABORT, OUString( OSL_LOG_PREFIX ) );
+ }
}
+ else
+ // no interaction, error handling as usual
+ aMedium.SetError( ERRCODE_IO_BROKENPACKAGE, OUString( OSL_LOG_PREFIX ) );
if ( !bRepairAllowed )
{
- // repair either not allowed or not successful
- // repair either not allowed or not successful
- NotifyBrokenPackage aNotifyRequest( aDocumentTitle );
- xInteraction->handle( aNotifyRequest.GetRequest() );
-
- Reference< ::comphelper::OIHWrapNoFilterDialog > xHandler = new ::comphelper::OIHWrapNoFilterDialog( xInteraction );
- if ( nIndexOfInteractionHandler != -1 )
- lDescriptor[nIndexOfInteractionHandler].Value <<= Reference< XInteractionHandler >( static_cast< XInteractionHandler* >( xHandler.get() ) );
-
- aMedium.SetError( ERRCODE_ABORT, OUString( OSL_LOG_PREFIX ) );
+ aTypeName = "";
+ aPreselectedFilterName = "";
}
}
- else
- // no interaction, error handling as usual
- aMedium.SetError( ERRCODE_IO_BROKENPACKAGE, OUString( OSL_LOG_PREFIX ) );
-
- if ( !bRepairAllowed )
- {
- aTypeName = "";
- aPreselectedFilterName = "";
- }
}
}
- catch (const RuntimeException&)
- {
- throw;
- }
- catch (const Exception&)
- {
- aTypeName = "";
- aPreselectedFilterName = "";
- }
}
- }
- else
- {
- aMedium.GetInStream();
- if ( aMedium.GetErrorCode() == ERRCODE_NONE )
+ else
{
- if ( !aPreselectedFilterName.isEmpty() )
- pFilter = SfxFilter::GetFilterByName( aPreselectedFilterName );
- else
- pFilter = SfxFilterMatcher().GetFilter4EA( aTypeName );
+ aMedium.GetInStream();
+ if ( aMedium.GetErrorCode() == ERRCODE_NONE )
+ {
+ if ( !aPreselectedFilterName.isEmpty() )
+ pFilter = SfxFilter::GetFilterByName( aPreselectedFilterName );
+ else
+ pFilter = SfxFilterMatcher().GetFilter4EA( aTypeName );
- bool bTestWriter = !pFilter || pFilter->GetServiceName() == "com.sun.star.text.TextDocument" ||
- pFilter->GetServiceName() == "com.sun.star.text.WebDocument";
- bool bTestGlobal = !pFilter || pFilter->GetServiceName() == "com.sun.star.text.GlobalDocument";
+ bool bTestWriter = !pFilter || pFilter->GetServiceName() == "com.sun.star.text.TextDocument" ||
+ pFilter->GetServiceName() == "com.sun.star.text.WebDocument";
+ bool bTestGlobal = !pFilter || pFilter->GetServiceName() == "com.sun.star.text.GlobalDocument";
- const SfxFilter* pOrigFilter = NULL;
- if ( !bTestWriter && !bTestGlobal && pFilter )
- {
- // cross filter; now this should be a type detection only, not a filter detection
- // we can simulate it by preserving the preselected filter if the type matches
- // example: HTML filter for Calc
- pOrigFilter = pFilter;
- pFilter = SfxFilterMatcher().GetFilter4EA( pFilter->GetTypeName() );
- bTestWriter = true;
+ const SfxFilter* pOrigFilter = NULL;
+ if ( !bTestWriter && !bTestGlobal && pFilter )
+ {
+ // cross filter; now this should be a type detection only, not a filter detection
+ // we can simulate it by preserving the preselected filter if the type matches
+ // example: HTML filter for Calc
+ pOrigFilter = pFilter;
+ pFilter = SfxFilterMatcher().GetFilter4EA( pFilter->GetTypeName() );
+ bTestWriter = true;
+ }
+
+ sal_uLong nErr = ERRCODE_NONE;
+ if ( pFilter || bTestWriter )
+ nErr = DetectFilter( aMedium, &pFilter );
+ if ( nErr != ERRCODE_NONE )
+ pFilter = NULL;
+ else if ( pOrigFilter && pFilter && pFilter->GetTypeName() == pOrigFilter->GetTypeName() )
+ // cross filter, see above
+ pFilter = pOrigFilter;
}
- sal_uLong nErr = ERRCODE_NONE;
- if ( pFilter || bTestWriter )
- nErr = DetectFilter( aMedium, &pFilter );
- if ( nErr != ERRCODE_NONE )
- pFilter = NULL;
- else if ( pOrigFilter && pFilter && pFilter->GetTypeName() == pOrigFilter->GetTypeName() )
- // cross filter, see above
- pFilter = pOrigFilter;
+ if ( pFilter )
+ aTypeName = pFilter->GetTypeName();
+ else
+ aTypeName = "";
}
-
- if ( pFilter )
- aTypeName = pFilter->GetTypeName();
- else
- aTypeName = "";
}
}
+ catch (const RuntimeException&)
+ {
+ throw;
+ }
+ catch (const Exception&)
+ {
+ aTypeName = "";
+ aPreselectedFilterName = "";
+ }
}
if ( nIndexOfInputStream == -1 && xStream.is() )