b326000
From 1f1715c086d8dcdf5165b19164af9aee7aa12e98 Mon Sep 17 00:00:00 2001
b326000
From: =?UTF-8?q?Dan=20=C4=8Cerm=C3=A1k?= <dan.cermak@cgc-instruments.com>
b326000
Date: Fri, 6 Oct 2017 00:37:43 +0200
b326000
Subject: =?UTF-8?q?Use=20nullptr=20check=20instead=20of=20assertion,=20by?=
b326000
 =?UTF-8?q?=20Rapha=C3=ABl=20Hertzog?=
b326000
MIME-Version: 1.0
b326000
Content-Type: text/plain; charset=UTF-8
b326000
Content-Transfer-Encoding: 8bit
b326000
b326000
Source:
b326000
https://github.com/Exiv2/exiv2/issues/57#issuecomment-333086302
b326000
b326000
tc can be a null pointer when the TIFF tag is unknown (the factory
b326000
then returns an auto_ptr(0)) => as this can happen for corrupted
b326000
files, an explicit check should be used because an assertion can be
b326000
turned of in release mode (with NDEBUG defined)
b326000
b326000
This also fixes #57
b326000
b326000
diff --git a/src/tiffvisitor.cpp b/src/tiffvisitor.cpp
b326000
index 74f8d078..4ab733d4 100644
b326000
--- a/src/tiffvisitor.cpp
b326000
+++ b/src/tiffvisitor.cpp
b326000
@@ -1294,11 +1294,12 @@ namespace Exiv2 {
b326000
             }
b326000
             uint16_t tag = getUShort(p, byteOrder());
b326000
             TiffComponent::AutoPtr tc = TiffCreator::create(tag, object->group());
b326000
-            // The assertion typically fails if a component is not configured in
b326000
-            // the TIFF structure table
b326000
-            assert(tc.get());
b326000
-            tc->setStart(p);
b326000
-            object->addChild(tc);
b326000
+            if (tc.get()) {
b326000
+                tc->setStart(p);
b326000
+                object->addChild(tc);
b326000
+            } else {
b326000
+               EXV_WARNING << "Unable to handle tag " << tag << ".\n";
b326000
+            }
b326000
             p += 12;
b326000
         }
b326000