-
Notifications
You must be signed in to change notification settings - Fork 0
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
SIGILLなテスト #2
Labels
bug
Something isn't working
Comments
|
多分次のコードで再現するはず: #[cfg(test)]
mod test {
#[test]
fn test() {
pretty_size(0);
}
fn pretty_size(bytes: usize) -> String {
let mut buf = [0u8; 5];
let mut rest = bytes;
let mut head_index: Option<NonZeroUsize> = None;
write_numeric_char(bytes, 1000, &mut buf, 0, &mut rest, &mut head_index);
write_numeric_char(bytes, 100, &mut buf, 1, &mut rest, &mut head_index);
write_numeric_char(bytes, 10, &mut buf, 2, &mut rest, &mut head_index);
write_numeric_char(bytes, 1, &mut buf, 3, &mut rest, &mut head_index);
buf[4] = b'B';
let head = unsafe { head_index.unwrap_unchecked() }.get() - 1;
unsafe { std::str::from_utf8_unchecked(&buf[head..]).to_string() }
}
fn write_numeric_char(n: usize, pow: usize, bytes: &mut [u8], byte_index: usize, r: &mut usize, head: &mut Option<NonZeroUsize>) {
if n >= pow {
bytes[byte_index] = convert_to_numeric_char(*r / pow);
*r -= *r / pow * pow;
head.get_or_insert_with(|| (unsafe { NonZeroUsize::new_unchecked(byte_index + 1) }));
}
}
fn convert_to_numeric_char(a: usize) -> u8 {
match a {
0 => b'0',
1 => b'1',
2 => b'2',
3 => b'3',
4 => b'4',
5 => b'5',
6 => b'6',
7 => b'7',
8 => b'8',
9 => b'9',
_ => unreachable!("{}", a)
}
}
} |
|
ただのUBだった |
|
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ときたま再現するの謎。 rust-lang/rust#69558 あたりが関連している?
The text was updated successfully, but these errors were encountered: