зеркало из https://github.com/mozilla/gecko-dev.git
Bug 328755 - Assigning a zero-length string should not alloc a buffer. r=bsmedberg
This commit is contained in:
Родитель
d4cdf301e3
Коммит
ee57f16151
|
@ -209,7 +209,10 @@ EncodeInputStream(nsIInputStream *aInputStream,
|
||||||
if (state.charsOnStack)
|
if (state.charsOnStack)
|
||||||
Encode(state.c, state.charsOnStack, state.buffer);
|
Encode(state.c, state.charsOnStack, state.buffer);
|
||||||
|
|
||||||
*aDest.EndWriting() = '\0';
|
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;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,6 +153,13 @@ int32_t nsUnescapeCount(char * str)
|
||||||
char* const pc1 = c1;
|
char* const pc1 = c1;
|
||||||
char* const pc2 = c2;
|
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)
|
while (*src)
|
||||||
{
|
{
|
||||||
c1[0] = *(src+1);
|
c1[0] = *(src+1);
|
||||||
|
|
|
@ -100,7 +100,7 @@ struct nsCharTraits<char16_t>
|
||||||
typedef uint16_t unsigned_char_type;
|
typedef uint16_t unsigned_char_type;
|
||||||
typedef char incompatible_char_type;
|
typedef char incompatible_char_type;
|
||||||
|
|
||||||
static char_type *sEmptyBuffer;
|
static char_type* const sEmptyBuffer;
|
||||||
|
|
||||||
static
|
static
|
||||||
void
|
void
|
||||||
|
@ -326,7 +326,7 @@ struct nsCharTraits<char>
|
||||||
typedef unsigned char unsigned_char_type;
|
typedef unsigned char unsigned_char_type;
|
||||||
typedef char16_t incompatible_char_type;
|
typedef char16_t incompatible_char_type;
|
||||||
|
|
||||||
static char_type *sEmptyBuffer;
|
static char_type* const sEmptyBuffer;
|
||||||
|
|
||||||
static
|
static
|
||||||
void
|
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;
|
char* const nsCharTraits<char>::sEmptyBuffer =
|
||||||
char16_t* nsCharTraits<char16_t>::sEmptyBuffer = &gNullChar;
|
(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
|
bool
|
||||||
nsTSubstring_CharT::Assign( const char_type* data, size_type length, const fallible_t& )
|
nsTSubstring_CharT::Assign( const char_type* data, size_type length, const fallible_t& )
|
||||||
{
|
{
|
||||||
if (!data)
|
if (!data || length == 0)
|
||||||
{
|
{
|
||||||
Truncate();
|
Truncate();
|
||||||
return true;
|
return true;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче