]> granicus.if.org Git - imagemagick/commitdiff
Use better method to determine the format from the file name.
authorDirk Lemstra <dirk@git.imagemagick.org>
Sun, 11 Mar 2018 09:22:50 +0000 (10:22 +0100)
committerDirk Lemstra <dirk@git.imagemagick.org>
Sun, 11 Mar 2018 09:22:50 +0000 (10:22 +0100)
Magick++/fuzz/encoder_format.h
Magick++/fuzz/main.cc

index 3f214b1966212d94c81d6cbc1d91659be2033b04..9d72179c947e830e6a8cbe74a3989521b15e0140 100644 (file)
@@ -1,10 +1,21 @@
 class EncoderFormat {
 public:
   std::string get() { return std::string(_format.begin(), _format.end()); } const
-  void set(const std::wstring format)
+  void set(const std::wstring fileName)
   {
-    if (format.length() > 1)
-      _format = format.substr(1, format.size() - 1);
+    std::wstring format=fileName;
+
+    size_t index = format.find(L"_", 0);
+    if (index != std::wstring::npos) {
+      format=format.substr(index + 1);
+      index = format.find(L"_", 0);
+      if (index != std::wstring::npos) {
+        _format=format.substr(0, index);
+        return;
+      }
+    }
+
+    throw std::invalid_argument("fileName");
   }
 private:
   std::wstring _format = L".notset";
index 31cf37e3e8b9e34daaa38da43062ba57285f78f6..bfc3e7092de3deb7aa29cbbc5385d0c3fcca4e03 100644 (file)
@@ -35,7 +35,7 @@ public:
     file.read(_data, size);
     file.close();
 
-    encoderFormat.set(wstring(PathFindExtension(fileName.c_str())));
+    encoderFormat.set(fileName);
 
     return(true);
   }