ByteVector::toUInt() takes offset and length
authorTsuda kageyu <tsuda.kageyu@gmail.com>
Thu, 18 Apr 2013 09:36:19 +0000 (18:36 +0900)
committerTsuda kageyu <tsuda.kageyu@gmail.com>
Thu, 18 Apr 2013 09:36:19 +0000 (18:36 +0900)
31 files changed:
taglib/ape/apefooter.cpp
taglib/ape/apeitem.cpp
taglib/ape/apeproperties.cpp
taglib/asf/asffile.cpp
taglib/asf/asfpicture.cpp
taglib/flac/flacfile.cpp
taglib/flac/flacpicture.cpp
taglib/flac/flacproperties.cpp
taglib/mp4/mp4atom.cpp
taglib/mp4/mp4properties.cpp
taglib/mp4/mp4tag.cpp
taglib/mpc/mpcproperties.cpp
taglib/mpeg/id3v2/frames/popularimeterframe.cpp
taglib/mpeg/id3v2/frames/relativevolumeframe.cpp
taglib/mpeg/id3v2/id3v2frame.cpp
taglib/mpeg/id3v2/id3v2synchdata.cpp
taglib/mpeg/xingheader.cpp
taglib/ogg/flac/oggflacfile.cpp
taglib/ogg/oggpageheader.cpp
taglib/ogg/opus/opusproperties.cpp
taglib/ogg/speex/speexproperties.cpp
taglib/ogg/vorbis/vorbisproperties.cpp
taglib/ogg/xiphcomment.cpp
taglib/riff/aiff/aiffproperties.cpp
taglib/riff/wav/infotag.cpp
taglib/riff/wav/wavproperties.cpp
taglib/toolkit/tbyteswap.cpp
taglib/toolkit/tbytevector.cpp
taglib/toolkit/tbytevector.h
taglib/trueaudio/trueaudioproperties.cpp
taglib/wavpack/wavpackproperties.cpp

index 688649016865255cee336c434eea4b3fe3baf3b3..539832bafa98052f139418cfcd026d9c0ae93288 100644 (file)
@@ -177,19 +177,19 @@ void APE::Footer::parse(const ByteVector &data)
 
   // Read the version number
 
-  d->version = data.mid(8, 4).toUInt(false);
+  d->version = data.toUInt(8, false);
 
   // Read the tag size
 
-  d->tagSize = data.mid(12, 4).toUInt(false);
+  d->tagSize = data.toUInt(12, false);
 
   // Read the item count
 
-  d->itemCount = data.mid(16, 4).toUInt(false);
+  d->itemCount = data.toUInt(16, false);
 
   // Read the flags
 
-  std::bitset<32> flags(TAGLIB_CONSTRUCT_BITSET(data.mid(20, 4).toUInt(false)));
+  std::bitset<32> flags(TAGLIB_CONSTRUCT_BITSET(data.toUInt(20, false)));
 
   d->headerPresent = flags[31];
   d->footerPresent = !flags[30];
index 9d9647ec3d7cb9eb13b308f898ae3aebd6ea94d9..b1670a65b4bf017af194ed12f137044308247d2c 100644 (file)
@@ -229,8 +229,8 @@ void APE::Item::parse(const ByteVector &data)
     return;
   }
 
-  uint valueLength  = data.mid(0, 4).toUInt(false);
-  uint flags        = data.mid(4, 4).toUInt(false);
+  const uint valueLength  = data.toUInt(0, false);
+  const uint flags        = data.toUInt(4, false);
 
   d->key = String(data.mid(8), String::UTF8);
 
index b4fcec6add67df0b0d5f3ed08965c557c6207ffb..4940edead41d99e2218c5c2e378538bf6968d44b 100644 (file)
@@ -125,10 +125,10 @@ void APE::Properties::read()
 
   // Then we read the header common for all versions of APE
   d->file->seek(offset);
-  ByteVector commonHeader=d->file->readBlock(6);
+  ByteVector commonHeader = d->file->readBlock(6);
   if(!commonHeader.startsWith("MAC "))
     return;
-  d->version = commonHeader.mid(4).toUInt(false);
+  d->version = commonHeader.toUShort(4, false);
 
   if(d->version >= 3980) {
     analyzeCurrent();
@@ -182,7 +182,7 @@ void APE::Properties::analyzeCurrent()
   // Read the descriptor
   d->file->seek(2, File::Current);
   ByteVector descriptor = d->file->readBlock(44);
-  uint descriptorBytes = descriptor.mid(0,4).toUInt(false);
+  const uint descriptorBytes = descriptor.toUInt(0, false);
 
   if ((descriptorBytes - 52) > 0)
     d->file->seek(descriptorBytes - 52, File::Current);
@@ -191,14 +191,14 @@ void APE::Properties::analyzeCurrent()
   ByteVector header = d->file->readBlock(24);
 
   // Get the APE info
-  d->channels = header.mid(18, 2).toShort(false);
-  d->sampleRate = header.mid(20, 4).toUInt(false);
-  d->bitsPerSample = header.mid(16, 2).toShort(false);
+  d->channels      = header.toShort(18, false);
+  d->sampleRate    = header.toUInt(20, false);
+  d->bitsPerSample = header.toShort(16, false);
   //d->compressionLevel =
 
-  uint totalFrames = header.mid(12, 4).toUInt(false);
-  uint blocksPerFrame = header.mid(4, 4).toUInt(false);
-  uint finalFrameBlocks = header.mid(8, 4).toUInt(false);
+  const uint totalFrames      = header.toUInt(12, false);
+  const uint blocksPerFrame   = header.toUInt(4, false);
+  const uint finalFrameBlocks = header.toUInt(8, false);
   d->sampleFrames = totalFrames > 0 ? (totalFrames -  1) * blocksPerFrame + finalFrameBlocks : 0;
   d->length = d->sampleRate > 0 ? d->sampleFrames / d->sampleRate : 0;
   d->bitrate = d->length > 0 ? ((d->streamLength * 8L) / d->length) / 1000 : 0;
@@ -207,13 +207,13 @@ void APE::Properties::analyzeCurrent()
 void APE::Properties::analyzeOld()
 {
   ByteVector header = d->file->readBlock(26);
-  uint totalFrames = header.mid(18, 4).toUInt(false);
+  const uint totalFrames = header.toUInt(18, false);
 
   // Fail on 0 length APE files (catches non-finalized APE files)
   if(totalFrames == 0)
     return;
 
-  short compressionLevel = header.mid(0, 2).toShort(false);
+  const short compressionLevel = header.toShort(0, false);
   uint blocksPerFrame;
   if(d->version >= 3950)
     blocksPerFrame = 73728 * 4;
@@ -221,10 +221,11 @@ void APE::Properties::analyzeOld()
     blocksPerFrame = 73728;
   else
     blocksPerFrame = 9216;
-  d->channels = header.mid(4, 2).toShort(false);
-  d->sampleRate = header.mid(6, 4).toUInt(false);
-  uint finalFrameBlocks = header.mid(22, 4).toUInt(false);
-  uint totalBlocks = totalFrames > 0 ? (totalFrames - 1) * blocksPerFrame + finalFrameBlocks : 0;
+  d->channels   = header.toShort(4, false);
+  d->sampleRate = header.toUInt(6, false);
+  const uint finalFrameBlocks = header.toUInt(22, false);
+  const uint totalBlocks 
+    = totalFrames > 0 ? (totalFrames - 1) * blocksPerFrame + finalFrameBlocks : 0;
   d->length = totalBlocks / d->sampleRate;
   d->bitrate = d->length > 0 ? ((d->streamLength * 8L) / d->length) / 1000 : 0;
 }
index eb0009249844d77c1b655bcc3a15ed8a62d9f636..56e93a76c7fd6eb5a3a5c2faca38cc66015ea53a 100644 (file)
@@ -187,7 +187,8 @@ ByteVector ASF::File::FilePropertiesObject::guid()
 void ASF::File::FilePropertiesObject::parse(ASF::File *file, uint size)
 {
   BaseObject::parse(file, size);
-  file->d->properties->setLength((int)(data.mid(40, 8).toLongLong(false) / 10000000L - data.mid(56, 8).toLongLong(false) / 1000L));
+  file->d->properties->setLength(
+    (int)(data.toLongLong(40, false) / 10000000L - data.toLongLong(56, false) / 1000L));
 }
 
 ByteVector ASF::File::StreamPropertiesObject::guid()
@@ -198,9 +199,9 @@ ByteVector ASF::File::StreamPropertiesObject::guid()
 void ASF::File::StreamPropertiesObject::parse(ASF::File *file, uint size)
 {
   BaseObject::parse(file, size);
-  file->d->properties->setChannels(data.mid(56, 2).toShort(false));
-  file->d->properties->setSampleRate(data.mid(58, 4).toUInt(false));
-  file->d->properties->setBitrate(data.mid(62, 4).toUInt(false) * 8 / 1000);
+  file->d->properties->setChannels(data.toShort(56, false));
+  file->d->properties->setSampleRate(data.toUInt(58, false));
+  file->d->properties->setBitrate(data.toUInt(62, false) * 8 / 1000);
 }
 
 ByteVector ASF::File::ContentDescriptionObject::guid()
index c36ffa3a92411df9b189b242b52108e1bae9a865..35e52a7d5062a59da27cd74b4d0b02097eba5bed 100644 (file)
@@ -149,7 +149,7 @@ void ASF::Picture::parse(const ByteVector& bytes)
     return;
   int pos = 0;
   d->type = (Type)bytes[0]; ++pos;
-  uint dataLen = bytes.mid(pos, 4).toUInt(false); pos+=4;
+  const uint dataLen = bytes.toUInt(pos, false); pos+=4;
 
   const ByteVector nullStringTerminator(2, 0);
 
index 972fe7287743526d9d985847a77bcb63f0c88bbe..9f6251cf828e74e8fd97af16981dda76484fa2c6 100644 (file)
@@ -399,7 +399,7 @@ void FLAC::File::scan()
 
   char blockType = header[0] & 0x7f;
   bool isLastBlock = (header[0] & 0x80) != 0;
-  uint length = header.mid(1, 3).toUInt();
+  uint length = header.toUInt(1U, 3U);
 
   // First block should be the stream_info metadata
 
@@ -419,7 +419,7 @@ void FLAC::File::scan()
     header = readBlock(4);
     blockType = header[0] & 0x7f;
     isLastBlock = (header[0] & 0x80) != 0;
-    length = header.mid(1, 3).toUInt();
+    length = header.toUInt(1U, 3U);
 
     ByteVector data = readBlock(length);
     if(data.size() != length || length == 0) {
index 36019248a67d3f045c490fea137209808784c8bd..95eeb6aba6dc49c91501aa45c4e1a3304c7430ae 100644 (file)
@@ -82,10 +82,10 @@ bool FLAC::Picture::parse(const ByteVector &data)
     return false;
   }
 
-  int pos = 0;
-  d->type = FLAC::Picture::Type(data.mid(pos, 4).toUInt());
+  uint pos = 0;
+  d->type = FLAC::Picture::Type(data.toUInt(pos));
   pos += 4;
-  uint mimeTypeLength = data.mid(pos, 4).toUInt();
+  uint mimeTypeLength = data.toUInt(pos);
   pos += 4;
   if(pos + mimeTypeLength + 24 > data.size()) {
     debug("Invalid picture block.");
@@ -93,7 +93,7 @@ bool FLAC::Picture::parse(const ByteVector &data)
   }
   d->mimeType = String(data.mid(pos, mimeTypeLength), String::UTF8);
   pos += mimeTypeLength;
-  uint descriptionLength = data.mid(pos, 4).toUInt();
+  uint descriptionLength = data.toUInt(pos);
   pos += 4;
   if(pos + descriptionLength + 20 > data.size()) {
     debug("Invalid picture block.");
@@ -101,15 +101,15 @@ bool FLAC::Picture::parse(const ByteVector &data)
   }
   d->description = String(data.mid(pos, descriptionLength), String::UTF8);
   pos += descriptionLength;
-  d->width = data.mid(pos, 4).toUInt();
+  d->width = data.toUInt(pos);
   pos += 4;
-  d->height = data.mid(pos, 4).toUInt();
+  d->height = data.toUInt(pos);
   pos += 4;
-  d->colorDepth = data.mid(pos, 4).toUInt();
+  d->colorDepth = data.toUInt(pos);
   pos += 4;
-  d->numColors = data.mid(pos, 4).toUInt();
+  d->numColors = data.toUInt(pos);
   pos += 4;
-  uint dataLength = data.mid(pos, 4).toUInt();
+  uint dataLength = data.toUInt(pos);
   pos += 4;
   if(pos + dataLength > data.size()) {
     debug("Invalid picture block.");
index 8bdc5d8dc19531085a178f772b50f909b5dc3c07..e591193ef9d3e40d8048909fab81dd793730fe67 100644 (file)
@@ -124,7 +124,7 @@ void FLAC::Properties::read()
     return;
   }
 
-  int pos = 0;
+  uint pos = 0;
 
   // Minimum block size (in samples)
   pos += 2;
@@ -138,7 +138,7 @@ void FLAC::Properties::read()
   // Maximum frame size (in bytes)
   pos += 3;
 
-  uint flags = d->data.mid(pos, 4).toUInt(true);
+  uint flags = d->data.toUInt(pos, true);
   pos += 4;
 
   d->sampleRate = flags >> 12;
@@ -149,7 +149,7 @@ void FLAC::Properties::read()
   // stream length in samples. (Audio files measured in days)
 
   unsigned long long hi = flags & 0xf;
-  unsigned long long lo = d->data.mid(pos, 4).toUInt(true);
+  unsigned long long lo = d->data.toUInt(pos, true);
   pos += 4;
 
   d->sampleFrames = (hi << 32) | lo;
index 1681ec805b431f719ed224a2afa800744147c33a..fac593b12e2d3b3c174897030dee3af89637df29 100644 (file)
@@ -52,10 +52,10 @@ MP4::Atom::Atom(File *file)
     return;
   }
 
-  length = header.mid(0, 4).toUInt();
+  length = header.toUInt();
 
   if (length == 1) {
-    long long longLength = file->readBlock(8).toLongLong();
+    const long long longLength = file->readBlock(8).toLongLong();
     if (longLength >= 8 && longLength <= 0xFFFFFFFF) {
         // The atom has a 64-bit length, but it's actually a 32-bit value
         length = (long)longLength;
index d2d04167c472b24c144cc752ad5b131826ca9cf7..e4e950720252ce5daac806441b0eea57f27f2bab 100644 (file)
@@ -96,8 +96,8 @@ MP4::Properties::Properties(File *file, MP4::Atoms *atoms, ReadStyle style)
       debug("MP4: Atom 'trak.mdia.mdhd' is smaller than expected");
       return;
     }
-    long long unit = data.mid(28, 8).toLongLong();
-    long long length = data.mid(36, 8).toLongLong();
+    const long long unit   = data.toLongLong(28U);
+    const long long length = data.toLongLong(36U);
     d->length = unit ? int(length / unit) : 0;
   }
   else {
@@ -105,8 +105,8 @@ MP4::Properties::Properties(File *file, MP4::Atoms *atoms, ReadStyle style)
       debug("MP4: Atom 'trak.mdia.mdhd' is smaller than expected");
       return;
     }
-    unsigned int unit = data.mid(20, 4).toUInt();
-    unsigned int length = data.mid(24, 4).toUInt();
+    const unsigned int unit   = data.toUInt(20U);
+    const unsigned int length = data.toUInt(24U);
     d->length = unit ? length / unit : 0;
   }
 
@@ -118,11 +118,11 @@ MP4::Properties::Properties(File *file, MP4::Atoms *atoms, ReadStyle style)
   file->seek(atom->offset);
   data = file->readBlock(atom->length);
   if(data.mid(20, 4) == "mp4a") {
-    d->channels = data.mid(40, 2).toShort();
-    d->bitsPerSample = data.mid(42, 2).toShort();
-    d->sampleRate = data.mid(46, 4).toUInt();
+    d->channels      = data.toShort(40U);
+    d->bitsPerSample = data.toShort(42U);
+    d->sampleRate    = data.toUInt(46U);
     if(data.mid(56, 4) == "esds" && data[64] == 0x03) {
-      long pos = 65;
+      uint pos = 65;
       if(data.mid(pos, 3) == "\x80\x80\x80") {
         pos += 3;
       }
@@ -133,16 +133,16 @@ MP4::Properties::Properties(File *file, MP4::Atoms *atoms, ReadStyle style)
           pos += 3;
         }
         pos += 10;
-        d->bitrate = (data.mid(pos, 4).toUInt() + 500) / 1000;
+        d->bitrate = (data.toUInt(pos) + 500) / 1000;
       }
     }
   }
   else if (data.mid(20, 4) == "alac") {
     if (atom->length == 88 && data.mid(56, 4) == "alac") {
       d->bitsPerSample = data.at(69);
-      d->channels = data.at(73);
-      d->bitrate = data.mid(80, 4).toUInt() / 1000;
-      d->sampleRate = data.mid(84, 4).toUInt();
+      d->channels   = data.at(73);
+      d->bitrate    = data.toUInt(80U) / 1000;
+      d->sampleRate = data.toUInt(84U);
     }
   }
 
index 3deb84b31f6bfaf6c7d54e3f31a0ea622edf11f5..df83796d4fa71e075476b6efcd4c31e69029dfdf 100644 (file)
@@ -114,9 +114,9 @@ MP4::Tag::parseData2(MP4::Atom *atom, TagLib::File *file, int expectedFlags, boo
   int i = 0;
   unsigned int pos = 0;
   while(pos < data.size()) {
-    int length = data.mid(pos, 4).toUInt();
+    const int length = static_cast<int>(data.toUInt(pos));
     ByteVector name = data.mid(pos + 4, 4);
-    int flags = data.mid(pos + 8, 4).toUInt();
+    const int flags = static_cast<int>(data.toUInt(pos + 8));
     if(freeForm && i < 2) {
       if(i == 0 && name != "mean") {
         debug("MP4: Unexpected atom \"" + name + "\", expecting \"mean\"");
@@ -207,8 +207,8 @@ MP4::Tag::parseIntPair(MP4::Atom *atom, TagLib::File *file)
 {
   ByteVectorList data = parseData(atom, file);
   if(data.size()) {
-    int a = data[0].mid(2, 2).toShort();
-    int b = data[0].mid(4, 2).toShort();
+    const int a = data[0].toShort(2U);
+    const int b = data[0].toShort(4U);
     addItem(atom->name, MP4::Item(a, b));
   }
 }
@@ -277,9 +277,9 @@ MP4::Tag::parseCovr(MP4::Atom *atom, TagLib::File *file)
   ByteVector data = file->readBlock(atom->length - 8);
   unsigned int pos = 0;
   while(pos < data.size()) {
-    int length = data.mid(pos, 4).toUInt();
+    const int length = static_cast<int>(data.toUInt(pos));
     ByteVector name = data.mid(pos + 4, 4);
-    int flags = data.mid(pos + 8, 4).toUInt();
+    const int flags = static_cast<int>(data.toUInt(pos + 8));
     if(name != "data") {
       debug("MP4: Unexpected atom \"" + name + "\", expecting \"data\"");
       break;
@@ -530,11 +530,11 @@ MP4::Tag::updateOffsets(long delta, long offset)
       }
       d->file->seek(atom->offset + 12);
       ByteVector data = d->file->readBlock(atom->length - 12);
-      unsigned int count = data.mid(0, 4).toUInt();
+      unsigned int count = data.toUInt();
       d->file->seek(atom->offset + 16);
-      int pos = 4;
+      uint pos = 4;
       while(count--) {
-        long o = data.mid(pos, 4).toUInt();
+        long o = static_cast<long>(data.toUInt(pos));
         if(o > offset) {
           o += delta;
         }
@@ -551,11 +551,11 @@ MP4::Tag::updateOffsets(long delta, long offset)
       }
       d->file->seek(atom->offset + 12);
       ByteVector data = d->file->readBlock(atom->length - 12);
-      unsigned int count = data.mid(0, 4).toUInt();
+      unsigned int count = data.toUInt();
       d->file->seek(atom->offset + 16);
-      int pos = 4;
+      uint pos = 4;
       while(count--) {
-        long long o = data.mid(pos, 8).toLongLong();
+        long long o = data.toLongLong(pos);
         if(o > offset) {
           o += delta;
         }
@@ -575,9 +575,9 @@ MP4::Tag::updateOffsets(long delta, long offset)
       }
       d->file->seek(atom->offset + 9);
       ByteVector data = d->file->readBlock(atom->length - 9);
-      unsigned int flags = (ByteVector(1, '\0') + data.mid(0, 3)).toUInt();
+      const unsigned int flags = data.toUInt(0, 3, true);
       if(flags & 1) {
-        long long o = data.mid(7, 8).toLongLong();
+        long long o = data.toLongLong(7U);
         if(o > offset) {
           o += delta;
         }
index 23d419872f0cdd9c72e428bddf2c24b26cb4a5b4..d406f8d7356b9caf2cdbed8386e0bb1a8a0b356c 100644 (file)
@@ -207,7 +207,7 @@ void MPC::Properties::readSV8(File *file)
       d->sampleFrames = readSize(data.mid(pos), pos);
       ulong begSilence = readSize(data.mid(pos), pos);
 
-      std::bitset<16> flags(TAGLIB_CONSTRUCT_BITSET(data.mid(pos, 2).toUShort(true)));
+      std::bitset<16> flags(TAGLIB_CONSTRUCT_BITSET(data.toUShort(pos, true)));
       pos += 2;
 
       d->sampleRate = sftable[flags[15] * 4 + flags[14] * 2 + flags[13]];
@@ -228,10 +228,10 @@ void MPC::Properties::readSV8(File *file)
 
       int replayGainVersion = data[0];
       if(replayGainVersion == 1) {
-        d->trackGain = data.mid(1, 2).toUInt(true);
-        d->trackPeak = data.mid(3, 2).toUInt(true);
-        d->albumGain = data.mid(5, 2).toUInt(true);
-        d->albumPeak = data.mid(7, 2).toUInt(true);
+        d->trackGain = data.toShort(1, true);
+        d->trackPeak = data.toShort(3, true);
+        d->albumGain = data.toShort(5, true);
+        d->albumPeak = data.toShort(7, true);
       }
     }
 
@@ -252,18 +252,18 @@ void MPC::Properties::readSV7(const ByteVector &data)
     if(d->version < 7)
       return;
 
-    d->totalFrames = data.mid(4, 4).toUInt(false);
+    d->totalFrames = data.toUInt(4, false);
 
-    std::bitset<32> flags(TAGLIB_CONSTRUCT_BITSET(data.mid(8, 4).toUInt(false)));
+    std::bitset<32> flags(TAGLIB_CONSTRUCT_BITSET(data.toUInt(8, false)));
     d->sampleRate = sftable[flags[17] * 2 + flags[16]];
     d->channels = 2;
 
-    uint gapless = data.mid(5, 4).toUInt(false);
+    uint gapless = data.toUInt(5, false);
 
-    d->trackGain = data.mid(14,2).toShort(false);
-    d->trackPeak = data.mid(12,2).toUInt(false);
-    d->albumGain = data.mid(18,2).toShort(false);
-    d->albumPeak = data.mid(16,2).toUInt(false);
+    d->trackGain = data.toShort(14, false);
+    d->trackPeak = data.toShort(12, false);
+    d->albumGain = data.toShort(18, false);
+    d->albumPeak = data.toShort(16, false);
 
     // convert gain info
     if(d->trackGain != 0) {
@@ -293,7 +293,7 @@ void MPC::Properties::readSV7(const ByteVector &data)
       d->sampleFrames = d->totalFrames * 1152 - 576;
   }
   else {
-    uint headerData = data.mid(0, 4).toUInt(false);
+    uint headerData = data.toUInt(0, false);
 
     d->bitrate = (headerData >> 23) & 0x01ff;
     d->version = (headerData >> 11) & 0x03ff;
@@ -301,9 +301,9 @@ void MPC::Properties::readSV7(const ByteVector &data)
     d->channels = 2;
 
     if(d->version >= 5)
-      d->totalFrames = data.mid(4, 4).toUInt(false);
+      d->totalFrames = data.toUInt(4, false);
     else
-      d->totalFrames = data.mid(6, 2).toUInt(false);
+      d->totalFrames = data.toUShort(6, false);
 
     d->sampleFrames = d->totalFrames * 1152 - 576;
   }
index cfe8c9f448c9eafd0852d9c4b974d0a40c4da8d3..3d4429f7d5710d90cab0f2f5c636c7bceb9ef920 100644 (file)
@@ -109,7 +109,7 @@ void PopularimeterFrame::parseFields(const ByteVector &data)
   if(pos < size) {
     d->rating = (unsigned char)(data[pos++]);
     if(pos < size) {
-      d->counter = data.mid(pos, 4).toUInt();
+      d->counter = data.toUInt(static_cast<uint>(pos));
     }
   }
 }
index 955b3ad03376b343c19af19248c1c52a575c4538..e3efbc380727898ff267d44e967088bc60ccbb82 100644 (file)
@@ -191,7 +191,7 @@ void RelativeVolumeFrame::parseFields(const ByteVector &data)
 
     ChannelData &channel = d->channels[type];
 
-    channel.volumeAdjustment = data.mid(pos, 2).toShort();
+    channel.volumeAdjustment = data.toShort(static_cast<uint>(pos));
     pos += 2;
 
     channel.peakVolume.bitsRepresentingPeak = data[pos];
index ddf6c5b58c22f5258ccfdfe8a15951ec8a56fc81..c5c5585d48a9c332602b67a11ff906b34628c60a 100644 (file)
@@ -642,7 +642,7 @@ void Frame::Header::setData(const ByteVector &data, uint version)
       return;
     }
 
-    d->frameSize = data.mid(3, 3).toUInt();
+    d->frameSize = data.toUInt(3, 3, true);
 
     break;
   }
@@ -670,7 +670,7 @@ void Frame::Header::setData(const ByteVector &data, uint version)
     // Set the size -- the frame size is the four bytes starting at byte four in
     // the frame header (structure 4)
 
-    d->frameSize = data.mid(4, 4).toUInt();
+    d->frameSize = data.toUInt(4U);
 
     { // read the first byte of flags
       std::bitset<8> flags(data[8]);
@@ -717,7 +717,7 @@ void Frame::Header::setData(const ByteVector &data, uint version)
     // iTunes writes v2.4 tags with v2.3-like frame sizes
     if(d->frameSize > 127) {
       if(!isValidFrameID(data.mid(d->frameSize + 10, 4))) {
-        unsigned int uintSize = data.mid(4, 4).toUInt();
+        unsigned int uintSize = data.toUInt(4U);
         if(isValidFrameID(data.mid(uintSize + 10, 4))) {
           d->frameSize = uintSize;
         }
index d4bab6795a28cc3b726e41a460675f599e6c034c..60698d3cb0962476a9017709a9001c89f645fc32 100644 (file)
@@ -49,7 +49,7 @@ TagLib::uint SynchData::toUInt(const ByteVector &data)
     // Invalid data; assume this was created by some buggy software that just
     // put normal integers here rather than syncsafe ones, and try it that
     // way.
-    sum = (data.size() > 4) ? data.mid(0, 4).toUInt() : data.toUInt();
+    sum = data.toUInt();
   }
 
   return sum;
index 1ba932de3cbf4daa8b70a2f17d221e5ce568192e..9e20127ee8d9c0915d5bede4e052bdf0cbe5fb62 100644 (file)
@@ -108,8 +108,8 @@ void MPEG::XingHeader::parse(const ByteVector &data)
     return;
   }
 
-  d->frames = data.mid(8, 4).toUInt();
-  d->size = data.mid(12, 4).toUInt();
+  d->frames = data.toUInt(8U);
+  d->size   = data.toUInt(12U);
 
   d->valid = true;
 }
index 510c01f8464f332ecd5a2615ce07ce7e53e59cfc..18506b2e6a223714aae3eddf80c9cebda2781868 100644 (file)
@@ -241,7 +241,7 @@ void Ogg::FLAC::File::scan()
 
   char blockType = header[0] & 0x7f;
   bool lastBlock = (header[0] & 0x80) != 0;
-  uint length = header.mid(1, 3).toUInt();
+  uint length = header.toUInt(1, 3, true);
   overhead += length;
 
   // Sanity: First block should be the stream_info metadata
@@ -251,7 +251,7 @@ void Ogg::FLAC::File::scan()
     return;
   }
 
-  d->streamInfoData = metadataHeader.mid(4,length);
+  d->streamInfoData = metadataHeader.mid(4, length);
 
   // Search through the remaining metadata
 
@@ -264,7 +264,7 @@ void Ogg::FLAC::File::scan()
     header = metadataHeader.mid(0, 4);
     blockType = header[0] & 0x7f;
     lastBlock = (header[0] & 0x80) != 0;
-    length = header.mid(1, 3).toUInt();
+    length = header.toUInt(1, 3, true);
     overhead += length;
 
     if(blockType == 1) {
index f9608ab7f74001f1443c01b43c00a1205a15a0c3..b933313548dc9bf5e94fab8ef0d8c0eca154250c 100644 (file)
@@ -255,9 +255,9 @@ void Ogg::PageHeader::read()
   d->firstPageOfStream = flags.test(1);
   d->lastPageOfStream = flags.test(2);
 
-  d->absoluteGranularPosition = data.mid(6, 8).toLongLong(false);
-  d->streamSerialNumber = data.mid(14, 4).toUInt(false);
-  d->pageSequenceNumber = data.mid(18, 4).toUInt(false);
+  d->absoluteGranularPosition = data.toLongLong(6, false);
+  d->streamSerialNumber = data.toUInt(14, false);
+  d->pageSequenceNumber = data.toUInt(18, false);
 
   // Byte number 27 is the number of page segments, which is the only variable
   // length portion of the page header.  After reading the number of page
index 70679d4cb3693fdb445122ebd84ae0355df9c070..7bdcd39dff200edc478d558831f323fe96dc0120 100644 (file)
@@ -118,7 +118,7 @@ void Opus::Properties::read()
   ByteVector data = d->file->packet(0);
 
   // *Magic Signature*
-  int pos = 8;
+  uint pos = 8;
 
   // *Version* (8 bits, unsigned)
   d->opusVersion = uchar(data.at(pos));
@@ -129,11 +129,11 @@ void Opus::Properties::read()
   pos += 1;
 
   // *Pre-skip* (16 bits, unsigned, little endian)
-  ushort preSkip = data.mid(pos, 2).toUShort(false);
+  const ushort preSkip = data.toUShort(pos, false);
   pos += 2;
 
   // *Input Sample Rate* (32 bits, unsigned, little endian)
-  d->inputSampleRate = data.mid(pos, 4).toUInt(false);
+  d->inputSampleRate = data.toUInt(pos, false);
   pos += 4;
 
   // *Output Gain* (16 bits, signed, little endian)
index 980f12dfd4c13f8af52cf1a39658e1fef7856cb8..5aaa915309be2475abc917b5addbb920dbfaf614 100644 (file)
@@ -113,32 +113,32 @@ void Speex::Properties::read()
 
   ByteVector data = d->file->packet(0);
 
-  int pos = 28;
+  uint pos = 28;
 
   // speex_version_id;       /**< Version for Speex (for checking compatibility) */
-  d->speexVersion = data.mid(pos, 4).toUInt(false);
+  d->speexVersion = data.toUInt(pos, false);
   pos += 4;
 
   // header_size;            /**< Total size of the header ( sizeof(SpeexHeader) ) */
   pos += 4;
 
   // rate;                   /**< Sampling rate used */
-  d->sampleRate = data.mid(pos, 4).toUInt(false);
+  d->sampleRate = data.toUInt(pos, false);
   pos += 4;
 
   // mode;                   /**< Mode used (0 for narrowband, 1 for wideband) */
-  d->mode = data.mid(pos, 4).toUInt(false);
+  d->mode = data.toUInt(pos, false);
   pos += 4;
 
   // mode_bitstream_version; /**< Version ID of the bit-stream */
   pos += 4;
 
   // nb_channels;            /**< Number of channels encoded */
-  d->channels = data.mid(pos, 4).toUInt(false);
+  d->channels = data.toUInt(pos, false);
   pos += 4;
 
   // bitrate;                /**< Bit-rate used */
-  d->bitrate = data.mid(pos, 4).toUInt(false);
+  d->bitrate = data.toUInt(pos, false);
   pos += 4;
 
   // frame_size;             /**< Size of frames */
@@ -146,7 +146,7 @@ void Speex::Properties::read()
   pos += 4;
 
   // vbr;                    /**< 1 for a VBR encoding, 0 otherwise */
-  d->vbr = data.mid(pos, 4).toUInt(false) == 1;
+  d->vbr = data.toUInt(pos, false) == 1;
   pos += 4;
 
   // frames_per_packet;      /**< Number of frames stored per Ogg packet */
index c67e16773e5372e48faef033a671f9f3c4dc9286..b5e88bfd0063b9c07a9ffd33cf25c33e7eb5738e 100644 (file)
@@ -133,7 +133,7 @@ void Vorbis::Properties::read()
 
   ByteVector data = d->file->packet(0);
 
-  int pos = 0;
+  uint pos = 0;
 
   if(data.mid(pos, 7) != vorbisSetupHeaderID) {
     debug("Vorbis::Properties::read() -- invalid Vorbis identification header");
@@ -142,22 +142,22 @@ void Vorbis::Properties::read()
 
   pos += 7;
 
-  d->vorbisVersion = data.mid(pos, 4).toUInt(false);
+  d->vorbisVersion = data.toUInt(pos, false);
   pos += 4;
 
   d->channels = uchar(data[pos]);
   pos += 1;
 
-  d->sampleRate = data.mid(pos, 4).toUInt(false);
+  d->sampleRate = data.toUInt(pos, false);
   pos += 4;
 
-  d->bitrateMaximum = data.mid(pos, 4).toUInt(false);
+  d->bitrateMaximum = data.toUInt(pos, false);
   pos += 4;
 
-  d->bitrateNominal = data.mid(pos, 4).toUInt(false);
+  d->bitrateNominal = data.toUInt(pos, false);
   pos += 4;
 
-  d->bitrateMinimum = data.mid(pos, 4).toUInt(false);
+  d->bitrateMinimum = data.toUInt(pos, false);
 
   // TODO: Later this should be only the "fast" mode.
   d->bitrate = d->bitrateNominal;
index 675614b3fb74cb6163bcc96db74aed3150f6f65c..51c2f9f0484931256c7e21aec8a512cf92a2fcb0 100644 (file)
@@ -340,7 +340,7 @@ void Ogg::XiphComment::parse(const ByteVector &data)
 
   uint pos = 0;
 
-  uint vendorLength = data.mid(0, 4).toUInt(false);
+  const uint vendorLength = data.toUInt(0, false);
   pos += 4;
 
   d->vendorID = String(data.mid(pos, vendorLength), String::UTF8);
@@ -348,7 +348,7 @@ void Ogg::XiphComment::parse(const ByteVector &data)
 
   // Next the number of fields in the comment vector.
 
-  uint commentFields = data.mid(pos, 4).toUInt(false);
+  const uint commentFields = data.toUInt(pos, false);
   pos += 4;
 
   if(commentFields > (data.size() - 8) / 4) {
@@ -360,7 +360,7 @@ void Ogg::XiphComment::parse(const ByteVector &data)
     // Each comment field is in the format "KEY=value" in a UTF8 string and has
     // 4 bytes before the text starts that gives the length.
 
-    uint commentLength = data.mid(pos, 4).toUInt(false);
+    const uint commentLength = data.toUInt(pos, false);
     pos += 4;
 
     String comment = String(data.mid(pos, commentLength), String::UTF8);
index 3ea275825d63fb49faac696f480ef8d44640dfec..1ed03d6bff5ea1201719a2b4f4dccecf47a72c7e 100644 (file)
@@ -150,9 +150,9 @@ TagLib::uint RIFF::AIFF::Properties::sampleFrames() const
 
 void RIFF::AIFF::Properties::read(const ByteVector &data)
 {
-  d->channels       = data.mid(0, 2).toShort();
-  d->sampleFrames   = data.mid(2, 4).toUInt();
-  d->sampleWidth    = data.mid(6, 2).toShort();
+  d->channels       = data.toShort(0U);
+  d->sampleFrames   = data.toUInt(2U);
+  d->sampleWidth    = data.toShort(6U);
   double sampleRate = ConvertFromIeeeExtended(reinterpret_cast<unsigned char *>(data.mid(8, 10).data()));
   d->sampleRate     = (int)sampleRate;
   d->bitrate        = (int)((sampleRate * d->sampleWidth * d->channels) / 1000.0);
index df1d2f8153975a6268d34a849c8d2a53c32e0d8e..5ce1df90722753a2548cbb459fdc353a20d91522 100644 (file)
@@ -249,7 +249,7 @@ void RIFF::Info::Tag::parse(const ByteVector &data)
 {
   uint p = 4;
   while(p < data.size()) {
-    uint size = data.mid(p + 4, 4).toUInt(false);
+    const uint size = data.toUInt(p + 4, false);
     d->fieldListMap[data.mid(p, 4)] = TagPrivate::stringHandler->parse(data.mid(p + 8, size));
 
     p += ((size + 1) & ~1) + 8;
index 9e7ea70ccc01ebb7ea39938517f367fa6a11551c..8062df5f7a9ab8f9801244a325a197af5aab97e8 100644 (file)
@@ -115,12 +115,12 @@ TagLib::uint RIFF::WAV::Properties::sampleFrames() const
 
 void RIFF::WAV::Properties::read(const ByteVector &data)
 {
-  d->format = data.mid(0, 2).toShort(false);
-  d->channels = data.mid(2, 2).toShort(false);
-  d->sampleRate = data.mid(4, 4).toUInt(false);
-  d->sampleWidth = data.mid(14, 2).toShort(false);
+  d->format      = data.toShort(0, false);
+  d->channels    = data.toShort(2, false);
+  d->sampleRate  = data.toUInt(4, false);
+  d->sampleWidth = data.toShort(14, false);
 
-  uint byteRate = data.mid(8, 4).toUInt(false);
+  const uint byteRate = data.toUInt(8, false);
   d->bitrate = byteRate * 8 / 1000;
 
   d->length = byteRate > 0 ? d->streamLength / byteRate : 0;
index 714033e8535064c0d406849a64700e05de0ab29e..cee2772db26229b62cb06673e606e5388ee483da 100644 (file)
@@ -191,7 +191,7 @@ namespace TagLib
 
 #else
 
-  const bool isLittleEndianSystem = isLittleEndianSystem();
+  const bool isLittleEndianSystem = isLittleEndian();
 
 #endif
 }
index ca65cfaa8b2c1b7812565eff9ec4d10936021e69..e6e8cb852577002b005531b65190fbd1054f5415 100644 (file)
  ***************************************************************************/
 
 #include <iostream>
+#include <cstdio>
+#include <cstring>
 #include <tstring.h>
 #include <tdebug.h>
-#include <string.h>
 
 #include "tbytevector.h"
 #include "tbyteswap.h"
@@ -201,24 +202,35 @@ ulonglong byteSwap<ulonglong>(ulonglong x)
 }
 
 template <class T>
-T toNumber(const ByteVector &v, bool mostSignificantByteFirst)
+T toNumber(const ByteVector &v, size_t offset, bool mostSignificantByteFirst)
 {
-  if(v.isEmpty()) {
-    debug("toNumber<T>() -- data is empty, returning 0");
+  if(offset + sizeof(T) > v.size()) {
+    debug("toNumber<T>() -- offset is out of range. Returning 0.");
     return 0;
   }
 
-  if(v.size() >= sizeof(T)) {
-    if(isLittleEndianSystem == mostSignificantByteFirst)
-      return byteSwap<T>(*reinterpret_cast<const T*>(v.data()));
-    else
-      return *reinterpret_cast<const T*>(v.data());
+  if(isLittleEndianSystem == mostSignificantByteFirst)
+    return byteSwap<T>(*reinterpret_cast<const T*>(v.data() + offset));
+  else
+    return *reinterpret_cast<const T*>(v.data() + offset);
+}
+
+template <class T>
+T toNumber(const ByteVector &v, size_t offset, size_t length, bool mostSignificantByteFirst)
+{
+  if(offset + length > v.size()) {
+    debug("toNumber<T>() -- offset and/or length is out of range. Returning 0.");
+    return 0;
+  }
+
+  if(length >= sizeof(T)) {
+    return toNumber<T>(v, offset, mostSignificantByteFirst);
   }
   else {
     T sum = 0;
-    for(size_t i = 0; i < v.size(); i++) {
-      const size_t shift = (mostSignificantByteFirst ? v.size() - 1 - i : i) * 8;
-      sum |= static_cast<T>(static_cast<uchar>(v[i]) << shift);
+    for(size_t i = 0; i < length; i++) {
+      const size_t shift = (mostSignificantByteFirst ? length - 1 - i : i) * 8;
+      sum |= static_cast<T>(static_cast<uchar>(v[offset + i]) << shift);
     }
 
     return sum;
@@ -441,11 +453,8 @@ const char *ByteVector::data() const
 
 ByteVector ByteVector::mid(uint index, uint length) const
 {
-  if(index > size())
-    index = size();
-
-  if(length > size() - index)
-    length = size() - index;
+  index  = std::min(index, size());
+  length = std::min(length, size() - index);
 
   return ByteVector(*this, index, length);
 }
@@ -687,22 +696,47 @@ TagLib::uint ByteVector::checksum() const
 
 TagLib::uint ByteVector::toUInt(bool mostSignificantByteFirst) const
 {
-  return toNumber<uint>(*this, mostSignificantByteFirst);
+  return toNumber<uint>(*this, 0, mostSignificantByteFirst);
+}
+
+TagLib::uint ByteVector::toUInt(uint offset, bool mostSignificantByteFirst) const
+{
+  return toNumber<uint>(*this, offset, mostSignificantByteFirst);
+}
+
+TagLib::uint ByteVector::toUInt(uint offset, uint length, bool mostSignificantByteFirst) const
+{
+  return toNumber<uint>(*this, offset, length, mostSignificantByteFirst);
 }
 
 short ByteVector::toShort(bool mostSignificantByteFirst) const
 {
-  return toNumber<unsigned short>(*this, mostSignificantByteFirst);
+  return toNumber<unsigned short>(*this, 0, mostSignificantByteFirst);
+}
+
+short ByteVector::toShort(uint offset, bool mostSignificantByteFirst) const
+{
+  return toNumber<unsigned short>(*this, offset, mostSignificantByteFirst);
 }
 
 unsigned short ByteVector::toUShort(bool mostSignificantByteFirst) const
 {
-  return toNumber<unsigned short>(*this, mostSignificantByteFirst);
+  return toNumber<unsigned short>(*this, 0, mostSignificantByteFirst);
+}
+
+unsigned short ByteVector::toUShort(uint offset, bool mostSignificantByteFirst) const
+{
+  return toNumber<unsigned short>(*this, offset, mostSignificantByteFirst);
 }
 
 long long ByteVector::toLongLong(bool mostSignificantByteFirst) const
 {
-  return toNumber<unsigned long long>(*this, mostSignificantByteFirst);
+  return toNumber<unsigned long long>(*this, 0, mostSignificantByteFirst);
+}
+
+long long ByteVector::toLongLong(uint offset, bool mostSignificantByteFirst) const
+{
+  return toNumber<unsigned long long>(*this, offset, mostSignificantByteFirst);
 }
 
 const char &ByteVector::operator[](int index) const
index ca810130f11244a46efe5d8ae9c7a2c9ce8245ef..4a0f2b91143b560fbe3ce2eb087e691f7c80f45e 100644 (file)
@@ -291,7 +291,32 @@ namespace TagLib {
     uint toUInt(bool mostSignificantByteFirst = true) const;
 
     /*!
-     * Converts the first 2 bytes of the vector to a short.
+     * Converts the 4 bytes at \a offset of the vector to an unsigned integer. 
+     *
+     * If \a mostSignificantByteFirst is true this will operate left to right
+     * evaluating the integer.  For example if \a mostSignificantByteFirst is
+     * true then $00 $00 $00 $01 == 0x00000001 == 1, if false, $01 00 00 00 ==
+     * 0x01000000 == 1.
+     *
+     * \see fromUInt()
+     */
+    uint toUInt(uint offset, bool mostSignificantByteFirst = true) const;
+
+    /*!
+     * Converts the \a length bytes at \a offset of the vector to an unsigned 
+     * integer. If \a length is larger than 4, the excess is ignored. 
+     *
+     * If \a mostSignificantByteFirst is true this will operate left to right
+     * evaluating the integer.  For example if \a mostSignificantByteFirst is
+     * true then $00 $00 $00 $01 == 0x00000001 == 1, if false, $01 00 00 00 ==
+     * 0x01000000 == 1.
+     *
+     * \see fromUInt()
+     */
+    uint toUInt(uint offset, uint length, bool mostSignificantByteFirst = true) const;
+
+    /*!
+     * Converts the first 2 bytes of the vector to a (signed) short.
      *
      * If \a mostSignificantByteFirst is true this will operate left to right
      * evaluating the integer.  For example if \a mostSignificantByteFirst is
@@ -301,6 +326,17 @@ namespace TagLib {
      */
     short toShort(bool mostSignificantByteFirst = true) const;
 
+    /*!
+     * Converts the 2 bytes at \a offset of the vector to a (signed) short.
+     *
+     * If \a mostSignificantByteFirst is true this will operate left to right
+     * evaluating the integer.  For example if \a mostSignificantByteFirst is
+     * true then $00 $01 == 0x0001 == 1, if false, $01 00 == 0x01000000 == 1.
+     *
+     * \see fromShort()
+     */
+    short toShort(uint offset, bool mostSignificantByteFirst = true) const;
+
     /*!
      * Converts the first 2 bytes of the vector to a unsigned short.
      *
@@ -312,6 +348,17 @@ namespace TagLib {
      */
     unsigned short toUShort(bool mostSignificantByteFirst = true) const;
 
+    /*!
+     * Converts the 2 bytes at \a offset of the vector to a unsigned short.
+     *
+     * If \a mostSignificantByteFirst is true this will operate left to right
+     * evaluating the integer.  For example if \a mostSignificantByteFirst is
+     * true then $00 $01 == 0x0001 == 1, if false, $01 00 == 0x01000000 == 1.
+     *
+     * \see fromShort()
+     */
+    unsigned short toUShort(uint offset, bool mostSignificantByteFirst = true) const;
+
     /*!
      * Converts the first 8 bytes of the vector to a (signed) long long.
      *
@@ -324,6 +371,18 @@ namespace TagLib {
      */
     long long toLongLong(bool mostSignificantByteFirst = true) const;
 
+    /*!
+     * Converts the 8 bytes at \a offset of the vector to a (signed) long long.
+     *
+     * If \a mostSignificantByteFirst is true this will operate left to right
+     * evaluating the integer.  For example if \a mostSignificantByteFirst is
+     * true then $00 00 00 00 00 00 00 01 == 0x0000000000000001 == 1,
+     * if false, $01 00 00 00 00 00 00 00 == 0x0100000000000000 == 1.
+     *
+     * \see fromUInt()
+     */
+    long long toLongLong(uint offset, bool mostSignificantByteFirst = true) const;
+
     /*!
      * Creates a 4 byte ByteVector based on \a value.  If
      * \a mostSignificantByteFirst is true, then this will operate left to right
index 9b251ff18e02f32c5c76697d2704b9fe3b192204..dedd74e94fd493721526471e194a12ee4ac23160 100644 (file)
@@ -133,16 +133,16 @@ void TrueAudio::Properties::read()
     // Skip the audio format
     pos += 2;
 
-    d->channels = d->data.mid(pos, 2).toShort(false);
+    d->channels = d->data.toShort(pos, false);
     pos += 2;
 
-    d->bitsPerSample = d->data.mid(pos, 2).toShort(false);
+    d->bitsPerSample = d->data.toShort(pos, false);
     pos += 2;
 
-    d->sampleRate = d->data.mid(pos, 4).toUInt(false);
+    d->sampleRate = d->data.toUInt(pos, false);
     pos += 4;
 
-    d->sampleFrames = d->data.mid(pos, 4).toUInt(false);
+    d->sampleFrames = d->data.toUInt(pos, false);
     d->length = d->sampleRate > 0 ? d->sampleFrames / d->sampleRate : 0;
 
     d->bitrate = d->length > 0 ? ((d->streamLength * 8L) / d->length) / 1000 : 0;
index 1715f425d0a7e7fc593c12f042d6d79e3137a4f5..3f7915443fb00a4bfda8d4fde7f86dac471ee366 100644 (file)
@@ -148,17 +148,17 @@ void WavPack::Properties::read()
   if(!d->data.startsWith("wvpk"))
     return;
 
-  d->version = d->data.mid(8, 2).toShort(false);
+  d->version = d->data.toShort(8, false);
   if(d->version < MIN_STREAM_VERS || d->version > MAX_STREAM_VERS)
     return;
 
-  unsigned int flags = d->data.mid(24, 4).toUInt(false);
+  const unsigned int flags = d->data.toUInt(24, false);
   d->bitsPerSample = ((flags & BYTES_STORED) + 1) * 8 -
     ((flags & SHIFT_MASK) >> SHIFT_LSB);
   d->sampleRate = sample_rates[(flags & SRATE_MASK) >> SRATE_LSB];
   d->channels = (flags & MONO_FLAG) ? 1 : 2;
 
-  unsigned int samples = d->data.mid(12, 4).toUInt(false);
+  unsigned int samples = d->data.toUInt(12, false);
   if(samples == ~0u) {
     if(d->file && d->style != Fast) {
       samples = seekFinalIndex();
@@ -186,14 +186,14 @@ unsigned int WavPack::Properties::seekFinalIndex()
     ByteVector data = d->file->readBlock(32);
     if(data.size() != 32)
       return 0;
-    int version = data.mid(8, 2).toShort(false);
+    const int version = data.toShort(8, false);
     if(version < MIN_STREAM_VERS || version > MAX_STREAM_VERS)
       continue;
-    unsigned int flags = data.mid(24, 4).toUInt(false);
+    const unsigned int flags = data.toUInt(24, false);
     if(!(flags & FINAL_BLOCK))
       return 0;
-    unsigned int blockIndex = data.mid(16, 4).toUInt(false);
-    unsigned int blockSamples = data.mid(20, 4).toUInt(false);
+    const unsigned int blockIndex   = data.toUInt(16, false);
+    const unsigned int blockSamples = data.toUInt(20, false);
     return blockIndex + blockSamples;
   }