diff options
| author | Ralf Jung <post@ralfj.de> | 2020-05-31 12:03:22 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-31 12:03:22 +0200 |
| commit | 3bbb475f0048b3ef009e31194c56d5265da65447 (patch) | |
| tree | 1a5500915564ff8a21c46c280bcf45ed442e840f /src/libstd | |
| parent | b6fa392238a459c29a47e2cf824d79a49a8ba039 (diff) | |
| parent | 0fb6e63c0438ace4ad9d496376af955c0baacf04 (diff) | |
| download | rust-3bbb475f0048b3ef009e31194c56d5265da65447.tar.gz rust-3bbb475f0048b3ef009e31194c56d5265da65447.zip | |
Rollup merge of #72683 - RalfJung:char-debug-check, r=Mark-Simulacrum
from_u32_unchecked: check validity, and fix UB in Wtf8 Fixes https://github.com/rust-lang/rust/issues/72760
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/lib.rs | 1 | ||||
| -rw-r--r-- | src/libstd/sys_common/wtf8.rs | 6 |
2 files changed, 3 insertions, 4 deletions
diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 9ddaa100c0e..d6493454db5 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -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)] diff --git a/src/libstd/sys_common/wtf8.rs b/src/libstd/sys_common/wtf8.rs index a5ba3daba3e..bdb6a05464e 100644 --- a/src/libstd/sys_common/wtf8.rs +++ b/src/libstd/sys_common/wtf8.rs @@ -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); self.bytes.extend_from_slice(bytes) } @@ -840,8 +839,7 @@ impl<'a> Iterator for EncodeWide<'a> { let mut buf = [0; 2]; self.code_points.next().map(|code_point| { - let c = unsafe { char::from_u32_unchecked(code_point.value) }; - let n = c.encode_utf16(&mut buf).len(); + let n = char::encode_utf16_raw(code_point.value, &mut buf).len(); if n == 2 { self.extra = buf[1]; } |
