mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 08:12:05 +00:00
Bug 328755 - Assigning a zero-length string should not alloc a buffer. r=bsmedberg
This commit is contained in:
parent
d4cdf301e3
commit
ee57f16151
@ -209,6 +209,9 @@ EncodeInputStream(nsIInputStream *aInputStream,
|
||||
if (state.charsOnStack)
|
||||
Encode(state.c, state.charsOnStack, state.buffer);
|
||||
|
||||
if (aDest.Length())
|
||||
// May belong to an nsCString with an unallocated buffer, so only null
|
||||
// terminate if there is a need to.
|
||||
*aDest.EndWriting() = '\0';
|
||||
|
||||
return NS_OK;
|
||||
|
@ -153,6 +153,13 @@ int32_t nsUnescapeCount(char * str)
|
||||
char* const pc1 = c1;
|
||||
char* const pc2 = c2;
|
||||
|
||||
if (!*src) {
|
||||
// A null string was passed in. Nothing to escape.
|
||||
// Returns early as the string might not actually be mutable with
|
||||
// length 0.
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (*src)
|
||||
{
|
||||
c1[0] = *(src+1);
|
||||
|
@ -100,7 +100,7 @@ struct nsCharTraits<char16_t>
|
||||
typedef uint16_t unsigned_char_type;
|
||||
typedef char incompatible_char_type;
|
||||
|
||||
static char_type *sEmptyBuffer;
|
||||
static char_type* const sEmptyBuffer;
|
||||
|
||||
static
|
||||
void
|
||||
@ -326,7 +326,7 @@ struct nsCharTraits<char>
|
||||
typedef unsigned char unsigned_char_type;
|
||||
typedef char16_t incompatible_char_type;
|
||||
|
||||
static char_type *sEmptyBuffer;
|
||||
static char_type* const sEmptyBuffer;
|
||||
|
||||
static
|
||||
void
|
||||
|
@ -40,10 +40,12 @@ using mozilla::Atomic;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
static char16_t gNullChar = 0;
|
||||
static const char16_t gNullChar = 0;
|
||||
|
||||
char* nsCharTraits<char> ::sEmptyBuffer = (char*) &gNullChar;
|
||||
char16_t* nsCharTraits<char16_t>::sEmptyBuffer = &gNullChar;
|
||||
char* const nsCharTraits<char>::sEmptyBuffer =
|
||||
(char*) const_cast<char16_t*>(&gNullChar);
|
||||
char16_t* const nsCharTraits<char16_t>::sEmptyBuffer =
|
||||
const_cast<char16_t*>(&gNullChar);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
|
@ -304,7 +304,7 @@ nsTSubstring_CharT::Assign( const char_type* data, size_type length )
|
||||
bool
|
||||
nsTSubstring_CharT::Assign( const char_type* data, size_type length, const fallible_t& )
|
||||
{
|
||||
if (!data)
|
||||
if (!data || length == 0)
|
||||
{
|
||||
Truncate();
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user