stylo: Backport rust-nsstring crash fixes to the vendored version.

This commit is contained in:
Emilio Cobos Álvarez 2017-03-03 17:33:55 +01:00
parent 5662af9057
commit feac01f793
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C

View file

@ -313,7 +313,7 @@ macro_rules! define_string_types {
assert!(s.len() < (u32::MAX as usize));
$String {
hdr: $StringRepr {
data: s.as_ptr(),
data: if s.is_empty() { ptr::null() } else { s.as_ptr()},
length: s.len() as u32,
flags: F_NONE,
},
@ -325,6 +325,11 @@ macro_rules! define_string_types {
impl From<Box<[$char_t]>> for $String<'static> {
fn from(s: Box<[$char_t]>) -> $String<'static> {
assert!(s.len() < (u32::MAX as usize));
if s.is_empty() {
return $String::new();
}
// SAFETY NOTE: This method produces an F_OWNED ns[C]String from
// a Box<[$char_t]>. this is only safe because in the Gecko
// tree, we use the same allocator for Rust code as for C++