mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
stylo: Backport rust-nsstring crash fixes to the vendored version.
This commit is contained in:
parent
5662af9057
commit
feac01f793
1 changed files with 6 additions and 1 deletions
|
@ -313,7 +313,7 @@ macro_rules! define_string_types {
|
||||||
assert!(s.len() < (u32::MAX as usize));
|
assert!(s.len() < (u32::MAX as usize));
|
||||||
$String {
|
$String {
|
||||||
hdr: $StringRepr {
|
hdr: $StringRepr {
|
||||||
data: s.as_ptr(),
|
data: if s.is_empty() { ptr::null() } else { s.as_ptr()},
|
||||||
length: s.len() as u32,
|
length: s.len() as u32,
|
||||||
flags: F_NONE,
|
flags: F_NONE,
|
||||||
},
|
},
|
||||||
|
@ -325,6 +325,11 @@ macro_rules! define_string_types {
|
||||||
impl From<Box<[$char_t]>> for $String<'static> {
|
impl From<Box<[$char_t]>> for $String<'static> {
|
||||||
fn from(s: Box<[$char_t]>) -> $String<'static> {
|
fn from(s: Box<[$char_t]>) -> $String<'static> {
|
||||||
assert!(s.len() < (u32::MAX as usize));
|
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
|
// SAFETY NOTE: This method produces an F_OWNED ns[C]String from
|
||||||
// a Box<[$char_t]>. this is only safe because in the Gecko
|
// a Box<[$char_t]>. this is only safe because in the Gecko
|
||||||
// tree, we use the same allocator for Rust code as for C++
|
// tree, we use the same allocator for Rust code as for C++
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue