From faae4178e85981bddaa7ec96f0eb344a26152fcd Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Fri, 4 Apr 2014 12:46:39 +0200 Subject: [PATCH] CpeId: NoThrowType remembers last malformed string causing an exception. --- tests/zypp/CpeId_test.cc | 3 +++ zypp/CpeId.cc | 12 ++++++++++-- zypp/CpeId.h | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/tests/zypp/CpeId_test.cc b/tests/zypp/CpeId_test.cc index 0da6baf..0456095 100644 --- a/tests/zypp/CpeId_test.cc +++ b/tests/zypp/CpeId_test.cc @@ -357,6 +357,9 @@ BOOST_AUTO_TEST_CASE(cpeid_basics) { BOOST_CHECK_THROW( CpeId( "malformed" ), std::invalid_argument ); CpeId none( "malformed", CpeId::noThrow ); + BOOST_CHECK_EQUAL( CpeId::NoThrowType::lastMalformed, "malformed" ); + CpeId( "", CpeId::noThrow ); + BOOST_CHECK_EQUAL( CpeId::NoThrowType::lastMalformed, "" ); for ( const auto & c : { CpeId(), CpeId( nullptr ), CpeId( "" ), CpeId( std::string() ) } ) { diff --git a/zypp/CpeId.cc b/zypp/CpeId.cc index 64277da..9be3d88 100644 --- a/zypp/CpeId.cc +++ b/zypp/CpeId.cc @@ -365,6 +365,8 @@ namespace zypp // class CpeId /////////////////////////////////////////////////////////////////// + std::string CpeId::NoThrowType::lastMalformed; + CpeId::CpeId() : _pimpl( new Impl ) {} @@ -376,9 +378,15 @@ namespace zypp CpeId::CpeId( const std::string & cpe_r, NoThrowType ) { try - { _pimpl.reset( new Impl( cpe_r ) ); } + { + _pimpl.reset( new Impl( cpe_r ) ); + NoThrowType::lastMalformed.clear(); + } catch(...) - { _pimpl.reset( new Impl ); } + { + _pimpl.reset( new Impl ); + NoThrowType::lastMalformed = cpe_r; + } } CpeId::~CpeId() diff --git a/zypp/CpeId.h b/zypp/CpeId.h index 40e1c63..a5204d1 100644 --- a/zypp/CpeId.h +++ b/zypp/CpeId.h @@ -57,7 +57,7 @@ namespace zypp public: /** Indicator type for non-trowing ctor. */ - struct NoThrowType {}; + struct NoThrowType { static std::string lastMalformed; }; /** Indicator argument for non-trowing ctor. */ static constexpr NoThrowType noThrow = NoThrowType(); -- 2.7.4