1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

MemoryOutputStream: Fix preallocating overly large buffer

This commit is contained in:
attila 2022-09-06 19:51:30 +02:00
parent c51bfd7429
commit bfe163cdad

View file

@ -172,7 +172,7 @@ bool MemoryOutputStream::setPosition (int64 newPosition)
int64 MemoryOutputStream::writeFromInputStream (InputStream& source, int64 maxNumBytesToWrite)
{
// before writing from an input, see if we can preallocate to make it more efficient..
int64 availableData = source.getTotalLength() - source.getPosition();
const auto availableData = source.getTotalLength() - source.getPosition();
if (availableData > 0)
{
@ -180,7 +180,7 @@ int64 MemoryOutputStream::writeFromInputStream (InputStream& source, int64 maxNu
maxNumBytesToWrite = availableData;
if (blockToUse != nullptr)
preallocate (blockToUse->getSize() + (size_t) maxNumBytesToWrite);
preallocate (position + (size_t) availableData);
}
return OutputStream::writeFromInputStream (source, maxNumBytesToWrite);