]> granicus.if.org Git - taglib/commitdiff
Add some debug messages to RIFF::File, just in case.
authorTsuda Kageyu <tsuda.kageyu@gmail.com>
Mon, 22 Feb 2016 14:17:17 +0000 (23:17 +0900)
committerTsuda Kageyu <tsuda.kageyu@gmail.com>
Mon, 22 Feb 2016 14:17:17 +0000 (23:17 +0900)
taglib/riff/rifffile.cpp

index 4b031ae25102bd35b2b57cf3da522ea44d08466a..f9d33e10dd8d6c666c94264b5dea9b601f371ad8 100644 (file)
@@ -100,31 +100,50 @@ unsigned int RIFF::File::chunkCount() const
 
 unsigned int RIFF::File::chunkDataSize(unsigned int i) const
 {
+  if(i >= d->chunks.size()) {
+    debug("RIFF::File::chunkPadding() - Index out of range. Returning 0.");
+    return 0;
+  }
+
   return d->chunks[i].size;
 }
 
 unsigned int RIFF::File::chunkOffset(unsigned int i) const
 {
+  if(i >= d->chunks.size()) {
+    debug("RIFF::File::chunkPadding() - Index out of range. Returning 0.");
+    return 0;
+  }
+
   return d->chunks[i].offset;
 }
 
 unsigned int RIFF::File::chunkPadding(unsigned int i) const
 {
+  if(i >= d->chunks.size()) {
+    debug("RIFF::File::chunkPadding() - Index out of range. Returning 0.");
+    return 0;
+  }
+
   return d->chunks[i].padding;
 }
 
 ByteVector RIFF::File::chunkName(unsigned int i) const
 {
-  if(i >= chunkCount())
+  if(i >= d->chunks.size()) {
+    debug("RIFF::File::chunkName() - Index out of range. Returning an empty vector.");
     return ByteVector();
+  }
 
   return d->chunks[i].name;
 }
 
 ByteVector RIFF::File::chunkData(unsigned int i)
 {
-  if(i >= chunkCount())
+  if(i >= d->chunks.size()) {
+    debug("RIFF::File::chunkData() - Index out of range. Returning an empty vector.");
     return ByteVector();
+  }
 
   seek(d->chunks[i].offset);
   return readBlock(d->chunks[i].size);
@@ -132,6 +151,11 @@ ByteVector RIFF::File::chunkData(unsigned int i)
 
 void RIFF::File::setChunkData(unsigned int i, const ByteVector &data)
 {
+  if(i >= d->chunks.size()) {
+    debug("RIFF::File::setChunkData() - Index out of range.");
+    return;
+  }
+
   // Now update the specific chunk
 
   std::vector<Chunk>::iterator it = d->chunks.begin();
@@ -223,6 +247,11 @@ void RIFF::File::setChunkData(const ByteVector &name, const ByteVector &data, bo
 
 void RIFF::File::removeChunk(unsigned int i)
 {
+  if(i >= d->chunks.size()) {
+    debug("RIFF::File::removeChunk() - Index out of range.");
+    return;
+  }
+
   std::vector<Chunk>::iterator it = d->chunks.begin();
   std::advance(it, i);