Skip to content

Commit

Permalink
handle str::from_utf8() failure, improve return calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Blumenkrantz committed Oct 13, 2014
1 parent 62deac9 commit 5bbce40
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions ports/cef/string.rs
Expand Up @@ -97,11 +97,16 @@ pub extern "C" fn cef_string_utf8_set(src: *const u8, src_len: size_t, output: *
pub extern "C" fn cef_string_utf8_to_utf16(src: *const u8, src_len: size_t, output: *mut cef_string_utf16_t) -> c_int {
unsafe {
slice::raw::buf_as_slice(src, src_len as uint, |result| {
let enc = str::from_utf8(result).unwrap().utf16_units().collect::<Vec<u16>>();
cef_string_utf16_set(enc.as_ptr(), enc.len() as size_t, output, 1);
});
match str::from_utf8(result) {
Some(enc) => {
let conv = enc.utf16_units().collect::<Vec<u16>>();
cef_string_utf16_set(conv.as_ptr(), conv.len() as size_t, output, 1);
1
},
None => 0
}
})
}
1
}

#[no_mangle]
Expand All @@ -111,15 +116,12 @@ pub extern "C" fn cef_string_utf16_to_utf8(src: *const u16, src_len: size_t, out
match string::String::from_utf16(ustr) {
Some(str) => {
cef_string_utf8_set(str.as_bytes().as_ptr(), str.len() as size_t, output, 1);
return 1 as c_int;
1 as c_int
},
None => {
return 0 as c_int;
}
None => 0 as c_int
}
});
})
}
1
}

#[no_mangle]
Expand Down

13 comments on commit 5bbce40

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from SimonSapin
at zmike@5bbce40

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging zmike/servo/embedding-encoding = 5bbce40 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zmike/servo/embedding-encoding = 5bbce40 merged ok, testing candidate = d1efe22

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from SimonSapin
at zmike@5bbce40

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging zmike/servo/embedding-encoding = 5bbce40 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zmike/servo/embedding-encoding = 5bbce40 merged ok, testing candidate = 6fa72c6

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from SimonSapin
at zmike@5bbce40

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging zmike/servo/embedding-encoding = 5bbce40 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zmike/servo/embedding-encoding = 5bbce40 merged ok, testing candidate = 686083e

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 686083e

Please sign in to comment.