mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-11 23:54:18 +00:00
Fixed a string allocation problem.
This commit is contained in:
parent
526ae27e8e
commit
5f00e94f3e
3 changed files with 11 additions and 7 deletions
|
|
@ -265,7 +265,7 @@ void MemoryBlock::copyTo (void* const dst, int offset, size_t num) const noexcep
|
|||
|
||||
String MemoryBlock::toString() const
|
||||
{
|
||||
return String (CharPointer_UTF8 (data), size);
|
||||
return String::fromUTF8 (data, size);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
|
|||
|
|
@ -175,8 +175,7 @@ String InputStream::readString()
|
|||
}
|
||||
}
|
||||
|
||||
return String (CharPointer_UTF8 (data),
|
||||
CharPointer_UTF8 (data + i));
|
||||
return String::fromUTF8 (data, i);
|
||||
}
|
||||
|
||||
String InputStream::readNextLine()
|
||||
|
|
|
|||
|
|
@ -1897,7 +1897,7 @@ struct StringEncodingConverter
|
|||
return CharPointerType_Dest (reinterpret_cast <const DestChar*> (&emptyChar));
|
||||
|
||||
CharPointerType_Src text (source.getCharPointer());
|
||||
const size_t extraBytesNeeded = CharPointerType_Dest::getBytesRequiredFor (text);
|
||||
const size_t extraBytesNeeded = CharPointerType_Dest::getBytesRequiredFor (text) + sizeof (typename CharPointerType_Dest::CharType);
|
||||
const size_t endOffset = (text.sizeInBytes() + 3) & ~3u; // the new string must be word-aligned or many Windows
|
||||
// functions will fail to read it correctly!
|
||||
source.preallocateBytes (endOffset + extraBytesNeeded);
|
||||
|
|
@ -1993,9 +1993,14 @@ String String::fromUTF8 (const char* const buffer, int bufferSizeBytes)
|
|||
{
|
||||
if (buffer != nullptr)
|
||||
{
|
||||
if (bufferSizeBytes < 0) return String (CharPointer_UTF8 (buffer));
|
||||
if (bufferSizeBytes > 0) return String (CharPointer_UTF8 (buffer),
|
||||
CharPointer_UTF8 (buffer + bufferSizeBytes));
|
||||
if (bufferSizeBytes < 0)
|
||||
return String (CharPointer_UTF8 (buffer));
|
||||
|
||||
if (bufferSizeBytes > 0)
|
||||
{
|
||||
jassert (CharPointer_UTF8::isValidString (buffer, bufferSizeBytes));
|
||||
return String (CharPointer_UTF8 (buffer), CharPointer_UTF8 (buffer + bufferSizeBytes));
|
||||
}
|
||||
}
|
||||
|
||||
return String();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue