]> granicus.if.org Git - taglib/commitdiff
Avoid searching the same area twice in MPEG::File::previousFrameOffset().
authorTsuda Kageyu <tsuda.kageyu@gmail.com>
Wed, 1 Feb 2017 05:23:03 +0000 (14:23 +0900)
committerTsuda Kageyu <tsuda.kageyu@gmail.com>
Wed, 1 Feb 2017 05:23:03 +0000 (14:23 +0900)
taglib/mpeg/mpegfile.cpp

index b8ff40ddd821d214144f51275387e449a363ec45..74bf779b62ed63051f8d88c985682a23c3ed7197 100644 (file)
@@ -373,15 +373,13 @@ long MPEG::File::previousFrameOffset(long position)
   ByteVector frameSyncBytes(2, '\0');
 
   while(position > 0) {
-    const long size = std::min<long>(position, bufferSize());
-    position -= size;
+    const long bufferLength = std::min<long>(position, bufferSize());
+    position -= bufferLength;
 
     seek(position);
-    const ByteVector buffer = readBlock(bufferSize());
-    if(buffer.isEmpty())
-      return -1;
+    const ByteVector buffer = readBlock(bufferLength);
 
-    for(int i = buffer.size() - 1; i >= 0; i--) {
+    for(int i = buffer.size() - 1; i >= 0; --i) {
       frameSyncBytes[1] = frameSyncBytes[0];
       frameSyncBytes[0] = buffer[i];
       if(isFrameSync(frameSyncBytes)) {