From 89fcab5669013bd46b0ef7b7f6efbb8a21cd1ceb Mon Sep 17 00:00:00 2001
From: Tsuda Kageyu <tsuda.kageyu@gmail.com>
Date: Wed, 17 Jul 2013 23:35:41 +0900
Subject: [PATCH] Fixed an MSVC specific runtime error only in debug mode

---
 taglib/toolkit/tbytevector.cpp | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/taglib/toolkit/tbytevector.cpp b/taglib/toolkit/tbytevector.cpp
index 0ea7517c..ddc3d4f4 100644
--- a/taglib/toolkit/tbytevector.cpp
+++ b/taglib/toolkit/tbytevector.cpp
@@ -156,9 +156,8 @@ int findVector(
   for(size_t i = 0; i < patternSize - 1; ++i)
     lastOccurrence[static_cast<uchar>(*(patternBegin + i))] = patternSize - i - 1;
 
-  for(TIterator it = dataBegin + patternSize - 1 + offset;
-    it < dataEnd;
-    it += lastOccurrence[static_cast<uchar>(*it)])
+  TIterator it = dataBegin + patternSize - 1 + offset;
+  while(true)
   {
     TIterator itBuffer = it;
     TIterator itPattern = patternBegin + patternSize - 1;
@@ -176,6 +175,12 @@ int findVector(
       --itBuffer;
       --itPattern;
     }
+
+    const size_t step = lastOccurrence[static_cast<uchar>(*it)];
+    if(dataEnd - step <= it)
+      break;
+
+    it += step;
   }
 
   return -1;
-- 
2.40.0