mirror of
https://github.com/taglib/taglib.git
synced 2025-06-03 09:08:09 -04:00
Make sure that we only write the number of bytes that we read.
BUG:122698 git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@689596 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
This commit is contained in:
parent
838114d093
commit
183060d729
@ -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.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user