From 72427dbebb41ee00a8139114e1a997fe011ff892 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Wed, 5 Aug 2020 00:40:54 +0800 Subject: [PATCH] runtime: cleanup core_log --- src/runtime/src/kernel/api.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/runtime/src/kernel/api.rs b/src/runtime/src/kernel/api.rs index 524cfe85..22752b66 100644 --- a/src/runtime/src/kernel/api.rs +++ b/src/runtime/src/kernel/api.rs @@ -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 mut buf = vec![0; size + 1]; 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), 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"); } }