1
0
Fork 0

runtime: cleanup core_log

This commit is contained in:
Sebastien Bourdeauducq 2020-08-05 00:40:54 +08:00
parent 6d654de3d5
commit 72427dbebb
1 changed files with 3 additions and 2 deletions

View File

@ -22,10 +22,11 @@ unsafe extern fn core_log(fmt: *const c_char, mut args: ...) {
let size = vsnprintf_(ptr::null_mut(), 0, fmt, args.as_va_list()) as usize; let size = vsnprintf_(ptr::null_mut(), 0, fmt, args.as_va_list()) as usize;
let mut buf = vec![0; size + 1]; let mut buf = vec![0; size + 1];
vsnprintf_(buf.as_mut_ptr() as *mut i8, size + 1, fmt, args.as_va_list()); vsnprintf_(buf.as_mut_ptr() as *mut i8, size + 1, fmt, args.as_va_list());
match str::from_utf8(buf.as_slice()) { let buf: &[u8] = &buf.as_slice()[..size-1]; // strip \n and NUL
match str::from_utf8(buf) {
Ok(s) => info!("kernel: {}", s), Ok(s) => info!("kernel: {}", s),
Err(e) => { Err(e) => {
info!("kernel: {}", (str::from_utf8(&buf.as_slice()[..e.valid_up_to()]).unwrap())); info!("kernel: {}", (str::from_utf8(&buf[..e.valid_up_to()]).unwrap()));
warn!("kernel: invalid utf-8"); warn!("kernel: invalid utf-8");
} }
} }