]> granicus.if.org Git - taglib/commitdiff
Make sure that we only write the number of bytes that we read.
authorScott Wheeler <wheeler@kde.org>
Wed, 18 Jul 2007 16:41:10 +0000 (16:41 +0000)
committerScott Wheeler <wheeler@kde.org>
Wed, 18 Jul 2007 16:41:10 +0000 (16:41 +0000)
BUG:122698

git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@689596 283d02a7-25f6-0310-bc7c-ecb5cbfe19da

taglib/toolkit/tfile.cpp

index 58533fe060f326cc28c105e214cfef8843bcde6b..2fa760776b806740e2eeeb49b45c2eec978667c0 100644 (file)
@@ -325,6 +325,7 @@ void File::insert(const ByteVector &data, ulong start, ulong replace)
   // that aren't yet in memory, so this is necessary.
 
   ulong bufferLength = bufferSize();
+
   while(data.size() - replace > bufferLength)
     bufferLength += bufferSize();
 
@@ -352,10 +353,14 @@ void File::insert(const ByteVector &data, ulong start, ulong replace)
 
   buffer = aboutToOverwrite;
 
+  // In case we've already reached the end of file...
+
+  buffer.resize(bytesRead);
+
   // Ok, here's the main loop.  We want to loop until the read fails, which
   // means that we hit the end of the file.
 
-  while(bytesRead != 0) {
+  while(!buffer.isEmpty()) {
 
     // Seek to the current read position and read the data that we're about
     // to overwrite.  Appropriately increment the readPosition.
@@ -375,8 +380,8 @@ void File::insert(const ByteVector &data, ulong start, ulong replace)
     // writePosition.
 
     seek(writePosition);
-    fwrite(buffer.data(), sizeof(char), bufferLength, d->file);
-    writePosition += bufferLength;
+    fwrite(buffer.data(), sizeof(char), buffer.size(), d->file);
+    writePosition += buffer.size();
 
     // Make the current buffer the data that we read in the beginning.