Skip to content

Commit d3a585e

Browse files
committed
Panic safety.
1 parent caf8bcc commit d3a585e

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

library/std/src/sys_common/wtf8.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,11 @@ impl Wtf8Buf {
220220
let surrogate = surrogate.unpaired_surrogate();
221221
// Surrogates are known to be in the code point range.
222222
let code_point = unsafe { CodePoint::from_u32_unchecked(surrogate as u32) };
223+
// The string will now contain an unpaired surrogate.
224+
string.is_known_utf8 = false;
223225
// Skip the WTF-8 concatenation check,
224226
// surrogate pairs are already decoded by decode_utf16
225227
string.push_code_point_unchecked(code_point);
226-
// The string now contains an unpaired surrogate.
227-
string.is_known_utf8 = false;
228228
}
229229
}
230230
}
@@ -346,13 +346,13 @@ impl Wtf8Buf {
346346
self.bytes.extend_from_slice(other_without_trail_surrogate);
347347
}
348348
_ => {
349-
self.bytes.extend_from_slice(&other.bytes);
350-
351-
// If we're pushing a string containing a surrogate, we may no
352-
// longer have UTF-8.
349+
// If we'll be pushing a string containing a surrogate, we may
350+
// no longer have UTF-8.
353351
if other.next_surrogate(0).is_some() {
354352
self.is_known_utf8 = false;
355353
}
354+
355+
self.bytes.extend_from_slice(&other.bytes);
356356
}
357357
}
358358
}
@@ -721,8 +721,8 @@ impl Wtf8 {
721721
}
722722

723723
pub fn clone_into(&self, buf: &mut Wtf8Buf) {
724-
self.bytes.clone_into(&mut buf.bytes);
725724
buf.is_known_utf8 = false;
725+
self.bytes.clone_into(&mut buf.bytes);
726726
}
727727

728728
/// Boxes this `Wtf8`.

0 commit comments

Comments
 (0)