diff --git a/include/exiv2/types.hpp b/include/exiv2/types.hpp index 3fcff9ab..a0f8a860 100644 --- a/include/exiv2/types.hpp +++ b/include/exiv2/types.hpp @@ -486,7 +486,7 @@ namespace Exiv2 { const T* find(T (&src)[N], const K& key) { const T* rc = std::find(src, src + N, key); - return rc == src + N ? 0 : rc; + return rc == src + N ? nullptr : rc; } //! Template used in the COUNTOF macro to determine the size of an array diff --git a/src/image.cpp b/src/image.cpp index 3086ab48..b1c5882d 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -920,10 +920,12 @@ namespace Exiv2 { { // BasicIo instance does not need to be open const Registry* r = find(registry, type); - if (nullptr != r) { - return r->newInstance_(std::move(io), true); + + if (r == nullptr || type == ImageType::none) { + return Image::UniquePtr(); } - return nullptr; + + return r->newInstance_(std::move(io), true); } // ***************************************************************************** diff --git a/unitTests/test_ImageFactory.cpp b/unitTests/test_ImageFactory.cpp index 51816680..515f5ed2 100644 --- a/unitTests/test_ImageFactory.cpp +++ b/unitTests/test_ImageFactory.cpp @@ -42,6 +42,11 @@ TEST(TheImageFactory, cannotCreateInstancesForSomeTypesInMemory) EXPECT_THROW(ImageFactory::create(ImageType::srw), Error); } +TEST(TheImageFactory, throwsWithImageTypeNone) +{ + EXPECT_THROW(ImageFactory::create(ImageType::none), Error); +} + TEST(TheImageFactory, throwsWithNonExistingImageTypes) { EXPECT_THROW(ImageFactory::create(static_cast(666)), Error);