workaround exif crash
[booh] / ext / rbbooh.cc
index 86ff86583f18776c3c55259f4bc9d93faac85f2e..e276442e7c637e9e8ee2f2e8e8bb394e4f5a6356 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <exiv2/image.hpp>
 #include <exiv2/exif.hpp>
+#include <exiv2/error.hpp>
 
 #define GDK_PIXBUF_ENABLE_BACKEND
 #include <gtk/gtk.h>
@@ -98,7 +99,7 @@ static VALUE exif_orientation(VALUE module, VALUE filename) {
                         return Qnil;
                 }
                 Exiv2::ExifData::const_iterator i = exifData.findKey(Exiv2::ExifKey("Exif.Image.Orientation"));
-                if (i != exifData.end()) {
+                if (i != exifData.end() && i->count() > 0) {
                         return INT2NUM(i->value().toLong());
                 }
                 return Qnil;
@@ -132,7 +133,7 @@ static VALUE exif_datetimeoriginal(VALUE module, VALUE filename) {
                         return Qnil;
                 }
                 Exiv2::ExifData::const_iterator i = exifData.findKey(Exiv2::ExifKey("Exif.Photo.DateTimeOriginal"));
-                if (i != exifData.end()) {
+                if (i != exifData.end() && i->count() > 0) {
                         return rb_str_new2(i->value().toString().c_str());
                 }
                 return Qnil;