Sort headers using clang-tidy
[geeqie.git] / src / exiv2.cc
index a8ff73d..6b9194d 100644 (file)
 #define HAVE_EXIV2_ERROR_CODE
 #endif
 
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
 #include <fcntl.h>
 #include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
 
 #if EXIV2_TEST_VERSION(0,27,0)
 #define EXV_PACKAGE "exiv2"
 
 #include <glib.h>
 
-#include "main.h"
 #include "exif.h"
 
+#include "debug.h"
 #include "filedata.h"
 #include "filefilter.h"
 #include "misc.h"
+#include "options.h"
 #include "ui-fileops.h"
 
 #if EXIV2_TEST_VERSION(0,28,0)
@@ -1219,19 +1220,13 @@ guchar *exif_get_preview(ExifData *exif, guint *data_len, gint requested_width,
 
                        Exiv2::PreviewImage image = pm.getPreviewImage(*pos);
 
-                       Exiv2::DataBuf buf = image.copy();
-
-#if EXIV2_TEST_VERSION(0,28,0)
-                       *data_len = buf.size();
-                       auto b = buf.data();
-                       buf.reset();
-                       return b;
-#else
-                       std::pair<Exiv2::byte*, long> p = buf.release();
-
-                       *data_len = p.second;
-                       return p.first;
-#endif
+                       // Let's not touch data_len until we finish copy.
+                       // Just in case we run into OOM.
+                       size_t img_sz = image.size();
+                       auto* b = new Exiv2::byte[img_sz];
+                       std::copy_n(image.pData(), img_sz, b);
+                       *data_len = img_sz;
+                       return b;
                        }
                return nullptr;
        }
@@ -1241,9 +1236,9 @@ guchar *exif_get_preview(ExifData *exif, guint *data_len, gint requested_width,
        }
 }
 
-void exif_free_preview(guchar *buf)
+void exif_free_preview(const guchar *buf)
 {
-       delete[] static_cast<Exiv2::byte*>(buf);
+delete[] static_cast<const Exiv2::byte*>(buf);
 }
 #endif
 
@@ -1338,7 +1333,7 @@ guchar *exif_get_preview(ExifData *exif, guint *data_len, gint requested_width,
 
 }
 
-void exif_free_preview(guchar *buf)
+void exif_free_preview(const guchar *buf)
 {
        GList *work = exif_unmap_list;