mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 328755 - Assigning a zero-length string should not alloc a buffer. r=bsmedberg
This commit is contained in:
parent
7a847783e0
commit
c75c6853ab
@ -208,7 +208,10 @@ EncodeInputStream(nsIInputStream *aInputStream,
|
||||
if (state.charsOnStack)
|
||||
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;
|
||||
}
|
||||
|
@ -181,7 +181,15 @@ int32_t nsUnescapeCount(char * str)
|
||||
}
|
||||
}
|
||||
|
||||
*dst = 0;
|
||||
/* The string may belong to a nsCString with an unallocated buffer.
|
||||
In such a situation the buffer points to a const char, so attempting
|
||||
to write to it will crash. This can be avoided by only null-terminating
|
||||
when needed. The above while loop is safe as it won't iterate when this
|
||||
occurs.
|
||||
*/
|
||||
if (*dst) {
|
||||
*dst = 0;
|
||||
}
|
||||
return (int)(dst - str);
|
||||
|
||||
} /* NET_UnEscapeCnt */
|
||||
|
@ -100,7 +100,7 @@ struct nsCharTraits<PRUnichar>
|
||||
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 PRUnichar incompatible_char_type;
|
||||
|
||||
static char_type *sEmptyBuffer;
|
||||
static char_type *const sEmptyBuffer;
|
||||
|
||||
static
|
||||
void
|
||||
|
@ -29,10 +29,12 @@ using mozilla::Atomic;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
static PRUnichar gNullChar = 0;
|
||||
static const PRUnichar gNullChar = 0;
|
||||
|
||||
char* nsCharTraits<char> ::sEmptyBuffer = (char*) &gNullChar;
|
||||
PRUnichar* nsCharTraits<PRUnichar>::sEmptyBuffer = &gNullChar;
|
||||
char* const nsCharTraits<char> ::sEmptyBuffer =
|
||||
(char*) const_cast<PRUnichar*>(&gNullChar);
|
||||
PRUnichar* const nsCharTraits<PRUnichar>::sEmptyBuffer =
|
||||
const_cast<PRUnichar*>(&gNullChar);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
|
@ -302,7 +302,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