Skip to content

from_u32_unchecked: check validity, and fix UB in Wtf8 #72683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 31, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
wtf8: use encode_utf8_raw
  • Loading branch information
RalfJung committed May 30, 2020
commit 3182cdf9baf8ed9e8ae24f4742ee5d3d01c2b54a
1 change: 1 addition & 0 deletions src/libstd/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@
#![feature(cfg_target_has_atomic)]
#![feature(cfg_target_thread_local)]
#![feature(char_error_internals)]
#![feature(char_internals)]
#![feature(clamp)]
#![feature(concat_idents)]
#![feature(const_cstr_unchecked)]
Expand Down
3 changes: 1 addition & 2 deletions src/libstd/sys_common/wtf8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,8 @@ impl Wtf8Buf {
/// Copied from String::push
/// This does **not** include the WTF-8 concatenation check.
fn push_code_point_unchecked(&mut self, code_point: CodePoint) {
let c = unsafe { char::from_u32_unchecked(code_point.value) };
let mut bytes = [0; 4];
let bytes = c.encode_utf8(&mut bytes).as_bytes();
let bytes = char::encode_utf8_raw(code_point.value, &mut bytes).as_bytes();
self.bytes.extend_from_slice(bytes)
}

Expand Down