[Libreoffice-commits] core.git: 2 commits - include/tools tools/source vcl/source xmlscript/source xmlsecurity/source
Noel Grandin
noel.grandin at collabora.co.uk
Wed Sep 27 07:06:32 UTC 2017
include/tools/fract.hxx | 9
tools/source/generic/fract.cxx | 24 +
vcl/source/app/unohelp2.cxx | 10
xmlscript/source/xml_helper/xml_impctx.cxx | 11
xmlscript/source/xmldlg_imexp/xmldlg_impmodels.cxx | 175 ++++-------
xmlscript/source/xmlflat_imexp/xmlbas_export.cxx | 16 -
xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx | 21 -
xmlsecurity/source/xmlsec/nss/nssinitializer.cxx | 20 -
xmlsecurity/source/xmlsec/nss/xmlsecuritycontext_nssimpl.cxx | 19 -
9 files changed, 143 insertions(+), 162 deletions(-)
New commits:
commit 595309903211ed5986ba0d2ef4d3b21bdfad10d9
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date: Tue Sep 26 12:47:54 2017 +0200
loplugin:flatten in vcl..xmlsecurity
Change-Id: I730fc0b3b6b7ac1803d75b5d9e007b15395888c6
Reviewed-on: https://gerrit.libreoffice.org/42826
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/vcl/source/app/unohelp2.cxx b/vcl/source/app/unohelp2.cxx
index a69dc1f8135e..80d829964819 100644
--- a/vcl/source/app/unohelp2.cxx
+++ b/vcl/source/app/unohelp2.cxx
@@ -71,18 +71,12 @@ namespace vcl { namespace unohelper {
// css::datatransfer::XTransferable
uno::Any TextDataObject::getTransferData( const datatransfer::DataFlavor& rFlavor )
{
- uno::Any aAny;
-
SotClipboardFormatId nT = SotExchange::GetFormat( rFlavor );
- if ( nT == SotClipboardFormatId::STRING )
- {
- aAny <<= maText;
- }
- else
+ if ( nT != SotClipboardFormatId::STRING )
{
throw datatransfer::UnsupportedFlavorException();
}
- return aAny;
+ return uno::Any(maText);
}
uno::Sequence< datatransfer::DataFlavor > TextDataObject::getTransferDataFlavors( )
diff --git a/xmlscript/source/xml_helper/xml_impctx.cxx b/xmlscript/source/xml_helper/xml_impctx.cxx
index 79d7889698b7..a51a99a57ed9 100644
--- a/xmlscript/source/xml_helper/xml_impctx.cxx
+++ b/xmlscript/source/xml_helper/xml_impctx.cxx
@@ -375,16 +375,13 @@ void DocumentHandlerImpl::initialize(
{
MGuard guard( m_pMutex );
Reference< xml::input::XRoot > xRoot;
- if (arguments.getLength() == 1 &&
- (arguments[ 0 ] >>= xRoot) &&
- xRoot.is())
- {
- m_xRoot = xRoot;
- }
- else
+ if (arguments.getLength() != 1 ||
+ !(arguments[ 0 ] >>= xRoot) ||
+ !xRoot.is())
{
throw RuntimeException( "missing root instance!" );
}
+ m_xRoot = xRoot;
}
// XNamespaceMapping
diff --git a/xmlscript/source/xmldlg_imexp/xmldlg_impmodels.cxx b/xmlscript/source/xmldlg_imexp/xmldlg_impmodels.cxx
index 5135761f8d49..4bc7152f957b 100644
--- a/xmlscript/source/xmldlg_imexp/xmldlg_impmodels.cxx
+++ b/xmlscript/source/xmldlg_imexp/xmldlg_impmodels.cxx
@@ -216,16 +216,15 @@ Reference< xml::input::XElement > ProgressBarElement::startChildElement(
Reference< xml::input::XAttributes > const & xAttributes )
{
// event
- if (m_xImport->isEventElement( nUid, rLocalName ))
- {
- return new EventElement(
- nUid, rLocalName, xAttributes, this, m_xImport.get() );
- }
- else
+ if (!m_xImport->isEventElement( nUid, rLocalName ))
{
throw xml::sax::SAXException( "expected event element!", Reference< XInterface >(), Any() );
}
+
+ return new EventElement(
+ nUid, rLocalName, xAttributes, this, m_xImport.get() );
}
+
void ProgressBarElement::endElement()
{
ControlImportContext ctx( m_xImport.get(), getControlId( _xAttributes ), "com.sun.star.awt.UnoControlProgressBarModel" );
@@ -258,15 +257,14 @@ Reference< xml::input::XElement > ScrollBarElement::startChildElement(
Reference< xml::input::XAttributes > const & xAttributes )
{
// event
- if (m_xImport->isEventElement( nUid, rLocalName ))
- {
- return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() );
- }
- else
+ if (!m_xImport->isEventElement( nUid, rLocalName ))
{
throw xml::sax::SAXException("expected event element!", Reference< XInterface >(), Any() );
}
+
+ return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() );
}
+
void ScrollBarElement::endElement()
{
ControlImportContext ctx( m_xImport.get(), getControlId( _xAttributes ), getControlModelName( "com.sun.star.awt.UnoControlScrollBarModel" , _xAttributes ) );
@@ -308,14 +306,12 @@ Reference< xml::input::XElement > SpinButtonElement::startChildElement(
Reference< xml::input::XAttributes > const & xAttributes )
{
// event
- if (m_xImport->isEventElement( nUid, rLocalName ))
- {
- return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() );
- }
- else
+ if (!m_xImport->isEventElement( nUid, rLocalName ))
{
throw xml::sax::SAXException("expected event element!", Reference< XInterface >(), Any() );
}
+
+ return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() );
}
void SpinButtonElement::endElement()
@@ -356,15 +352,14 @@ Reference< xml::input::XElement > FixedLineElement::startChildElement(
Reference< xml::input::XAttributes > const & xAttributes )
{
// event
- if (m_xImport->isEventElement( nUid, rLocalName ))
- {
- return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() );
- }
- else
+ if (!m_xImport->isEventElement( nUid, rLocalName ))
{
throw xml::sax::SAXException("expected event element!", Reference< XInterface >(), Any() );
}
+
+ return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() );
}
+
void FixedLineElement::endElement()
{
ControlImportContext ctx(m_xImport.get(), getControlId( _xAttributes ), "com.sun.star.awt.UnoControlFixedLineModel" );
@@ -396,15 +391,14 @@ Reference< xml::input::XElement > PatternFieldElement::startChildElement(
Reference< xml::input::XAttributes > const & xAttributes )
{
// event
- if (m_xImport->isEventElement( nUid, rLocalName ))
- {
- return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() );
- }
- else
+ if (!m_xImport->isEventElement( nUid, rLocalName ))
{
throw xml::sax::SAXException("expected event element!", Reference< XInterface >(), Any() );
}
+
+ return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() );
}
+
void PatternFieldElement::endElement()
{
ControlImportContext ctx( m_xImport.get(), getControlId( _xAttributes ), "com.sun.star.awt.UnoControlPatternFieldModel" );
@@ -444,14 +438,12 @@ Reference< xml::input::XElement > FormattedFieldElement::startChildElement(
Reference< xml::input::XAttributes > const & xAttributes )
{
// event
- if (m_xImport->isEventElement( nUid, rLocalName ))
- {
- return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() );
- }
- else
+ if (!m_xImport->isEventElement( nUid, rLocalName ))
{
throw xml::sax::SAXException("expected event element!", Reference< XInterface >(), Any() );
}
+
+ return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() );
}
void FormattedFieldElement::endElement()
@@ -572,15 +564,14 @@ Reference< xml::input::XElement > TimeFieldElement::startChildElement(
Reference< xml::input::XAttributes > const & xAttributes )
{
// event
- if (m_xImport->isEventElement( nUid, rLocalName ))
- {
- return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() );
- }
- else
+ if (!m_xImport->isEventElement( nUid, rLocalName ))
{
throw xml::sax::SAXException("expected event element!", Reference< XInterface >(), Any() );
}
+
+ return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() );
}
+
void TimeFieldElement::endElement()
{
ControlImportContext ctx( m_xImport.get(), getControlId( _xAttributes ), "com.sun.star.awt.UnoControlTimeFieldModel" );
@@ -626,15 +617,14 @@ Reference< xml::input::XElement > NumericFieldElement::startChildElement(
Reference< xml::input::XAttributes > const & xAttributes )
{
// event
- if (m_xImport->isEventElement( nUid, rLocalName ))
- {
- return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() );
- }
- else
+ if (!m_xImport->isEventElement( nUid, rLocalName ))
{
throw xml::sax::SAXException( "expected event element!", Reference< XInterface >(), Any() );
}
+
+ return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() );
}
+
void NumericFieldElement::endElement()
{
ControlImportContext ctx( m_xImport.get(), getControlId( _xAttributes ), "com.sun.star.awt.UnoControlNumericFieldModel" );
@@ -682,15 +672,14 @@ Reference< xml::input::XElement > DateFieldElement::startChildElement(
Reference< xml::input::XAttributes > const & xAttributes )
{
// event
- if (m_xImport->isEventElement( nUid, rLocalName ))
- {
- return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() );
- }
- else
+ if (!m_xImport->isEventElement( nUid, rLocalName ))
{
throw xml::sax::SAXException("expected event element!", Reference< XInterface >(), Any() );
}
+
+ return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() );
}
+
void DateFieldElement::endElement()
{
ControlImportContext ctx( m_xImport.get(), getControlId( _xAttributes ), "com.sun.star.awt.UnoControlDateFieldModel" );
@@ -737,15 +726,14 @@ Reference< xml::input::XElement > CurrencyFieldElement::startChildElement(
Reference< xml::input::XAttributes > const & xAttributes )
{
// event
- if (m_xImport->isEventElement( nUid, rLocalName ))
- {
- return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() );
- }
- else
+ if (!m_xImport->isEventElement( nUid, rLocalName ))
{
throw xml::sax::SAXException( "expected event element!" , Reference< XInterface >(), Any() );
}
+
+ return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() );
}
+
void CurrencyFieldElement::endElement()
{
ControlImportContext ctx( m_xImport.get(), getControlId( _xAttributes ), "com.sun.star.awt.UnoControlCurrencyFieldModel" );
@@ -793,15 +781,14 @@ Reference< xml::input::XElement > FileControlElement::startChildElement(
Reference< xml::input::XAttributes > const & xAttributes )
{
// event
- if (m_xImport->isEventElement( nUid, rLocalName ))
- {
- return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() );
- }
- else
+ if (!m_xImport->isEventElement( nUid, rLocalName ))
{
throw xml::sax::SAXException( "expected event element!", Reference< XInterface >(), Any() );
}
+
+ return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() );
}
+
void FileControlElement::endElement()
{
ControlImportContext ctx( m_xImport.get(), getControlId( _xAttributes ), "com.sun.star.awt.UnoControlFileControlModel" );
@@ -837,15 +824,14 @@ Reference< xml::input::XElement > TreeControlElement::startChildElement(
Reference< xml::input::XAttributes > const & xAttributes )
{
// event
- if (m_xImport->isEventElement( nUid, rLocalName ))
- {
- return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() );
- }
- else
+ if (!m_xImport->isEventElement( nUid, rLocalName ))
{
throw xml::sax::SAXException( "expected event element!", Reference< XInterface >(), Any() );
}
+
+ return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() );
}
+
void TreeControlElement::endElement()
{
ControlImportContext ctx( m_xImport.get(), getControlId( _xAttributes ), "com.sun.star.awt.tree.TreeControlModel" );
@@ -883,14 +869,12 @@ Reference< xml::input::XElement > ImageControlElement::startChildElement(
Reference< xml::input::XAttributes > const & xAttributes )
{
// event
- if (m_xImport->isEventElement( nUid, rLocalName ))
- {
- return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() );
- }
- else
+ if (!m_xImport->isEventElement( nUid, rLocalName ))
{
throw xml::sax::SAXException( "expected event element!" , Reference< XInterface >(), Any() );
}
+
+ return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() );
}
void ImageControlElement::endElement()
@@ -925,14 +909,12 @@ Reference< xml::input::XElement > TextElement::startChildElement(
Reference< xml::input::XAttributes > const & xAttributes )
{
// event
- if (m_xImport->isEventElement( nUid, rLocalName ))
- {
- return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() );
- }
- else
+ if (!m_xImport->isEventElement( nUid, rLocalName ))
{
throw xml::sax::SAXException( "expected event element!", Reference< XInterface >(), Any() );
}
+
+ return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() );
}
void TextElement::endElement()
@@ -972,15 +954,14 @@ Reference< xml::input::XElement > FixedHyperLinkElement::startChildElement(
Reference< xml::input::XAttributes > const & xAttributes )
{
// event
- if (m_xImport->isEventElement( nUid, rLocalName ))
- {
- return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() );
- }
- else
+ if (!m_xImport->isEventElement( nUid, rLocalName ))
{
throw xml::sax::SAXException( "expected event element!" , Reference< XInterface >(), Any() );
}
+
+ return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() );
}
+
void FixedHyperLinkElement::endElement()
{
ControlImportContext ctx( m_xImport.get(), getControlId( _xAttributes ), "com.sun.star.awt.UnoControlFixedHyperlinkModel" );
@@ -1021,15 +1002,14 @@ Reference< xml::input::XElement > TextFieldElement::startChildElement(
Reference< xml::input::XAttributes > const & xAttributes )
{
// event
- if (m_xImport->isEventElement( nUid, rLocalName ))
- {
- return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() );
- }
- else
+ if (!m_xImport->isEventElement( nUid, rLocalName ))
{
throw xml::sax::SAXException( "expected event element!", Reference< XInterface >(), Any() );
}
+
+ return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() );
}
+
void TextFieldElement::endElement()
{
ControlImportContext ctx( m_xImport.get(), getControlId( _xAttributes ), "com.sun.star.awt.UnoControlEditModel" );
@@ -1203,14 +1183,12 @@ Reference< xml::input::XElement > RadioElement::startChildElement(
Reference< xml::input::XAttributes > const & xAttributes )
{
// event
- if (m_xImport->isEventElement( nUid, rLocalName ))
- {
- return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() );
- }
- else
+ if (!m_xImport->isEventElement( nUid, rLocalName ))
{
throw xml::sax::SAXException("expected event element!", Reference< XInterface >(), Any() );
}
+
+ return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() );
}
// radiogroup
@@ -1484,15 +1462,14 @@ Reference< xml::input::XElement > CheckBoxElement::startChildElement(
Reference< xml::input::XAttributes > const & xAttributes )
{
// event
- if (m_xImport->isEventElement( nUid, rLocalName ))
- {
- return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() );
- }
- else
+ if (!m_xImport->isEventElement( nUid, rLocalName ))
{
throw xml::sax::SAXException( "expected event element!", Reference< XInterface >(), Any() );
}
+
+ return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() );
}
+
void CheckBoxElement::endElement()
{
ControlImportContext ctx( m_xImport.get(), getControlId( _xAttributes ), "com.sun.star.awt.UnoControlCheckBoxModel" );
@@ -1550,14 +1527,12 @@ Reference< xml::input::XElement > ButtonElement::startChildElement(
Reference< xml::input::XAttributes > const & xAttributes )
{
// event
- if (m_xImport->isEventElement( nUid, rLocalName ))
- {
- return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() );
- }
- else
+ if (!m_xImport->isEventElement( nUid, rLocalName ))
{
throw xml::sax::SAXException( "expected event element!", Reference< XInterface >(), Any() );
}
+
+ return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() );
}
void ButtonElement::endElement()
@@ -1777,14 +1752,12 @@ Reference< xml::input::XElement > StyleElement::startChildElement(
void StyleElement::endElement()
{
OUString aStyleId( _xAttributes->getValueByUidName( m_xImport->XMLNS_DIALOGS_UID, "style-id" ) );
- if (!aStyleId.isEmpty())
- {
- m_xImport->addStyle( aStyleId, this );
- }
- else
+ if (aStyleId.isEmpty())
{
throw xml::sax::SAXException( "missing style-id attribute!", Reference< XInterface >(), Any() );
}
+
+ m_xImport->addStyle( aStyleId, this );
}
// styles
diff --git a/xmlscript/source/xmlflat_imexp/xmlbas_export.cxx b/xmlscript/source/xmlflat_imexp/xmlbas_export.cxx
index 48e14115ea8e..a0793905a54c 100644
--- a/xmlscript/source/xmlflat_imexp/xmlbas_export.cxx
+++ b/xmlscript/source/xmlflat_imexp/xmlbas_export.cxx
@@ -62,18 +62,16 @@ namespace xmlscript
{
::osl::MutexGuard aGuard( m_aMutex );
- if ( aArguments.getLength() == 1 )
+ if ( aArguments.getLength() != 1 )
{
- aArguments[0] >>= m_xHandler;
-
- if ( !m_xHandler.is() )
- {
- throw RuntimeException( "XMLBasicExporterBase::initialize: invalid argument format!" );
- }
+ throw RuntimeException( "XMLBasicExporterBase::initialize: invalid number of arguments!" );
}
- else
+
+ aArguments[0] >>= m_xHandler;
+
+ if ( !m_xHandler.is() )
{
- throw RuntimeException( "XMLBasicExporterBase::initialize: invalid number of arguments!" );
+ throw RuntimeException( "XMLBasicExporterBase::initialize: invalid argument format!" );
}
}
diff --git a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
index 073ac07d44d4..10f7d0779d2b 100644
--- a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
+++ b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
@@ -87,21 +87,18 @@ namespace
{
OUString sDef("ODF/DefaultVersion");
Sequence< css::uno::Any > aValues = GetProperties( Sequence<OUString>(&sDef,1) );
- if ( aValues.getLength() == 1)
- {
- sal_Int16 nTmp = 0;
- if ( aValues[0] >>= nTmp )
- m_nODF = nTmp;
- else
- throw uno::RuntimeException(
- "[xmlsecurity]SaveODFItem::SaveODFItem(): Wrong Type!",
- nullptr );
-
- }
- else
+ if ( aValues.getLength() != 1)
throw uno::RuntimeException(
"[xmlsecurity] Could not open property Office.Common/Save/ODF/DefaultVersion",
nullptr);
+
+ sal_Int16 nTmp = 0;
+ if ( !(aValues[0] >>= nTmp) )
+ throw uno::RuntimeException(
+ "[xmlsecurity]SaveODFItem::SaveODFItem(): Wrong Type!",
+ nullptr );
+
+ m_nODF = nTmp;
}
}
diff --git a/xmlsecurity/source/xmlsec/nss/nssinitializer.cxx b/xmlsecurity/source/xmlsec/nss/nssinitializer.cxx
index a996ce5d43f4..dd6336578ea4 100644
--- a/xmlsecurity/source/xmlsec/nss/nssinitializer.cxx
+++ b/xmlsecurity/source/xmlsec/nss/nssinitializer.cxx
@@ -441,19 +441,17 @@ css::uno::Reference< css::xml::crypto::XCipherContext > SAL_CALL ONSSInitializer
{
CK_MECHANISM_TYPE nNSSCipherID = 0;
bool bW3CPadding = false;
- if ( nCipherID == css::xml::crypto::CipherID::AES_CBC_W3C_PADDING )
- {
- nNSSCipherID = CKM_AES_CBC;
- bW3CPadding = true;
+ if ( nCipherID != css::xml::crypto::CipherID::AES_CBC_W3C_PADDING )
+ throw css::lang::IllegalArgumentException("Unexpected cipher requested.", css::uno::Reference< css::uno::XInterface >(), 1 );
- if ( aKey.getLength() != 16 && aKey.getLength() != 24 && aKey.getLength() != 32 )
- throw css::lang::IllegalArgumentException("Unexpected key length.", css::uno::Reference< css::uno::XInterface >(), 2 );
+ nNSSCipherID = CKM_AES_CBC;
+ bW3CPadding = true;
- if ( aParams.getLength() )
- throw css::lang::IllegalArgumentException("Unexpected arguments provided for cipher creation.", css::uno::Reference< css::uno::XInterface >(), 5 );
- }
- else
- throw css::lang::IllegalArgumentException("Unexpected cipher requested.", css::uno::Reference< css::uno::XInterface >(), 1 );
+ if ( aKey.getLength() != 16 && aKey.getLength() != 24 && aKey.getLength() != 32 )
+ throw css::lang::IllegalArgumentException("Unexpected key length.", css::uno::Reference< css::uno::XInterface >(), 2 );
+
+ if ( aParams.getLength() )
+ throw css::lang::IllegalArgumentException("Unexpected arguments provided for cipher creation.", css::uno::Reference< css::uno::XInterface >(), 5 );
css::uno::Reference< css::xml::crypto::XCipherContext > xResult;
if( initNSS( m_xContext ) )
diff --git a/xmlsecurity/source/xmlsec/nss/xmlsecuritycontext_nssimpl.cxx b/xmlsecurity/source/xmlsec/nss/xmlsecuritycontext_nssimpl.cxx
index 371a27f3d090..d01eb3ffa692 100644
--- a/xmlsecurity/source/xmlsec/nss/xmlsecuritycontext_nssimpl.cxx
+++ b/xmlsecurity/source/xmlsec/nss/xmlsecuritycontext_nssimpl.cxx
@@ -62,25 +62,20 @@ sal_Int32 SAL_CALL XMLSecurityContext_NssImpl::getSecurityEnvironmentNumber( )
css::uno::Reference< css::xml::crypto::XSecurityEnvironment > SAL_CALL
XMLSecurityContext_NssImpl::getSecurityEnvironmentByIndex( sal_Int32 index )
{
- css::uno::Reference< css::xml::crypto::XSecurityEnvironment > xSecurityEnvironment;
-
- if (index >= 0 && index < ( sal_Int32 )m_vSecurityEnvironments.size())
- {
- xSecurityEnvironment = m_vSecurityEnvironments[index];
- }
- else
- throw RuntimeException() ;
+ if (index < 0 || index >= ( sal_Int32 )m_vSecurityEnvironments.size())
+ throw RuntimeException();
+ css::uno::Reference< css::xml::crypto::XSecurityEnvironment > xSecurityEnvironment = m_vSecurityEnvironments[index];
return xSecurityEnvironment;
}
css::uno::Reference< css::xml::crypto::XSecurityEnvironment > SAL_CALL
XMLSecurityContext_NssImpl::getSecurityEnvironment( )
{
- if (m_nDefaultEnvIndex >= 0 && m_nDefaultEnvIndex < ( sal_Int32 )m_vSecurityEnvironments.size())
- return getSecurityEnvironmentByIndex(m_nDefaultEnvIndex);
- else
- throw RuntimeException() ;
+ if (m_nDefaultEnvIndex < 0 || m_nDefaultEnvIndex >= ( sal_Int32 )m_vSecurityEnvironments.size())
+ throw RuntimeException();
+
+ return getSecurityEnvironmentByIndex(m_nDefaultEnvIndex);
}
sal_Int32 SAL_CALL XMLSecurityContext_NssImpl::getDefaultSecurityEnvironmentIndex( )
commit cdd211d0a3f8bf977ecca67e72afbc63d53a72ee
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date: Tue Sep 26 12:49:50 2017 +0200
check for NaN in Fraction
which can result from division by zero in earlier code, rather assert
explicitly than suffer from weird very large sal_Int64 values (which is
what NaN converts to, if we let it do the implicit conversion)
Change-Id: Id059b84906bbc90a4fa51489ca96dc0267bb9342
Reviewed-on: https://gerrit.libreoffice.org/42798
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/include/tools/fract.hxx b/include/tools/fract.hxx
index 68c0984a19a5..95aa5f5e727b 100644
--- a/include/tools/fract.hxx
+++ b/include/tools/fract.hxx
@@ -22,6 +22,7 @@
#include <sal/types.h>
#include <tools/toolsdllapi.h>
#include <memory>
+#include <type_traits>
class SvStream;
@@ -37,8 +38,14 @@ public:
Fraction();
Fraction( const Fraction & rFrac );
Fraction( Fraction && rFrac );
- Fraction( sal_Int64 nNum, sal_Int64 nDen );
explicit Fraction( double dVal );
+ Fraction( double nNum, double nDen );
+ Fraction( sal_Int64 nNum, sal_Int64 nDen );
+ // just to prevent ambiguity between the sal_Int64 and double constructors
+ template<typename T1, typename T2> Fraction(
+ T1 nNum, T2 nDen,
+ typename std::enable_if<std::is_integral<T1>::value && std::is_integral<T2>::value, int>::type = 0)
+ : Fraction( sal_Int64(nNum), sal_Int64(nDen) ) {}
~Fraction();
bool IsValid() const;
diff --git a/tools/source/generic/fract.cxx b/tools/source/generic/fract.cxx
index 7d89ae812e6f..1a78d4dfc654 100644
--- a/tools/source/generic/fract.cxx
+++ b/tools/source/generic/fract.cxx
@@ -86,6 +86,27 @@ Fraction::Fraction( sal_Int64 nNum, sal_Int64 nDen ) : mpImpl(new Impl)
mpImpl->valid = true;
}
+/**
+ * only here to prevent passing of NaN
+ */
+Fraction::Fraction( double nNum, double nDen ) : mpImpl(new Impl)
+{
+ assert( !std::isnan(nNum) );
+ assert( !std::isnan(nDen) );
+ assert( nNum >= std::numeric_limits<sal_Int32>::min() );
+ assert( nNum <= std::numeric_limits<sal_Int32>::max( ));
+ assert( nDen >= std::numeric_limits<sal_Int32>::min() );
+ assert( nDen <= std::numeric_limits<sal_Int32>::max( ));
+ if ( nDen == 0 )
+ {
+ mpImpl->valid = false;
+ SAL_WARN( "tools.fraction", "'Fraction(" << nNum << ",0)' invalid fraction created" );
+ return;
+ }
+ mpImpl->value.assign( sal_Int64(nNum), sal_Int64(nDen));
+ mpImpl->valid = true;
+}
+
Fraction::Fraction( double dVal ) : mpImpl(new Impl)
{
try
@@ -439,7 +460,8 @@ SvStream& WriteFraction( SvStream& rOStream, const Fraction& rFract )
static boost::rational<sal_Int32> rational_FromDouble(double dVal)
{
if ( dVal > std::numeric_limits<sal_Int32>::max() ||
- dVal < std::numeric_limits<sal_Int32>::min() )
+ dVal < std::numeric_limits<sal_Int32>::min() ||
+ std::isnan(dVal) )
throw boost::bad_rational();
const sal_Int32 nMAX = std::numeric_limits<sal_Int32>::max() / 10;
More information about the Libreoffice-commits
mailing list