servo: Merge #4136 - ports/cef: Replace calls to malloc with calloc (from pcwalton:cef-calloc); r=metajack

r? @metajack

Source-Repo: https://github.com/servo/servo
Source-Revision: 791606bde79cf38ae8484882a7986a1f258957a4
This commit is contained in:
Patrick Walton 2014-12-02 14:39:51 -07:00
Родитель 8b0b657cb0
Коммит 4b99bc08fd
2 изменённых файлов: 8 добавлений и 7 удалений

Просмотреть файл

@ -75,7 +75,7 @@ pub extern "C" fn cef_string_utf8_clear(cs: *mut cef_string_utf8_t) {
#[no_mangle]
pub extern "C" fn cef_string_userfree_utf8_alloc() -> *mut cef_string_utf8_t {
unsafe {
libc::malloc(mem::size_of::<cef_string_utf8_t>() as u64) as *mut cef_string_utf8_t
libc::calloc(1, mem::size_of::<cef_string_utf8_t>() as u64) as *mut cef_string_utf8_t
}
}
@ -85,7 +85,7 @@ pub extern "C" fn cef_string_utf8_set(src: *const u8, src_len: size_t, output: *
unsafe {
if copy != 0 {
if !src.is_null() && src_len > 0 {
(*output).str = libc::malloc(src_len + 1) as *mut u8;
(*output).str = libc::calloc(1, src_len + 1) as *mut u8;
if (*output).str.is_null() {
return 0;
}
@ -156,7 +156,7 @@ pub extern "C" fn cef_string_utf16_clear(cs: *mut cef_string_utf16_t) {
#[no_mangle]
pub extern "C" fn cef_string_userfree_utf16_alloc() -> *mut cef_string_utf16_t {
unsafe {
libc::malloc(mem::size_of::<cef_string_utf16_t>() as u64) as *mut cef_string_utf16_t
libc::calloc(1, mem::size_of::<cef_string_utf16_t>() as u64) as *mut cef_string_utf16_t
}
}
@ -166,7 +166,7 @@ pub extern "C" fn cef_string_utf16_set(src: *const c_ushort, src_len: size_t, ou
unsafe {
if copy != 0 {
if !src.is_null() && src_len > 0 {
(*output).str = libc::malloc((src_len + 1) * mem::size_of::<c_ushort>() as u64) as
(*output).str = libc::calloc(1, (src_len + 1) * mem::size_of::<c_ushort>() as u64) as
*mut u16;
if (*output).str.is_null() {
return 0;
@ -214,7 +214,7 @@ pub extern "C" fn cef_string_wide_clear(cs: *mut cef_string_wide_t) {
#[no_mangle]
pub extern "C" fn cef_string_userfree_wide_alloc() -> *mut cef_string_wide_t {
unsafe {
libc::malloc(mem::size_of::<cef_string_wide_t>() as u64) as *mut cef_string_wide_t
libc::calloc(1, mem::size_of::<cef_string_wide_t>() as u64) as *mut cef_string_wide_t
}
}
@ -224,7 +224,7 @@ pub extern "C" fn cef_string_wide_set(src: *const wchar_t, src_len: size_t, outp
unsafe {
if copy != 0 {
if !src.is_null() && src_len > 0 {
(*output).str = libc::malloc((src_len + 1) * mem::size_of::<wchar_t>() as u64) as
(*output).str = libc::calloc(1, (src_len + 1) * mem::size_of::<wchar_t>() as u64) as
*mut wchar_t;
if (*output).str.is_null() {
return 0;

Просмотреть файл

@ -181,7 +181,8 @@ cef_unimplemented_wrapper!(cef_string_t, String)
impl<'a> CefWrap<*const cef_string_t> for &'a [u16] {
fn to_c(buffer: &'a [u16]) -> *const cef_string_t {
unsafe {
let ptr: *mut c_ushort = mem::transmute(libc::malloc(((buffer.len() * 2) + 1) as u64));
let ptr: *mut c_ushort =
mem::transmute(libc::calloc(1, ((buffer.len() * 2) + 1) as u64));
ptr::copy_memory(ptr, mem::transmute(buffer.as_ptr()), (buffer.len() * 2) as uint);
*ptr.offset(buffer.len() as int) = 0;