bug: Fix crash when calling ImageFactory::create(none)

main
Luis Díaz Más 6 years ago
parent 012ce835c2
commit f10283f118

@ -486,7 +486,7 @@ namespace Exiv2 {
const T* find(T (&src)[N], const K& key) const T* find(T (&src)[N], const K& key)
{ {
const T* rc = std::find(src, src + N, 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 //! Template used in the COUNTOF macro to determine the size of an array

@ -920,10 +920,12 @@ namespace Exiv2 {
{ {
// BasicIo instance does not need to be open // BasicIo instance does not need to be open
const Registry* r = find(registry, type); 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);
} }
// ***************************************************************************** // *****************************************************************************

@ -42,6 +42,11 @@ TEST(TheImageFactory, cannotCreateInstancesForSomeTypesInMemory)
EXPECT_THROW(ImageFactory::create(ImageType::srw), Error); EXPECT_THROW(ImageFactory::create(ImageType::srw), Error);
} }
TEST(TheImageFactory, throwsWithImageTypeNone)
{
EXPECT_THROW(ImageFactory::create(ImageType::none), Error);
}
TEST(TheImageFactory, throwsWithNonExistingImageTypes) TEST(TheImageFactory, throwsWithNonExistingImageTypes)
{ {
EXPECT_THROW(ImageFactory::create(static_cast<ImageType>(666)), Error); EXPECT_THROW(ImageFactory::create(static_cast<ImageType>(666)), Error);

Loading…
Cancel
Save