We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d8be469 commit 2804036Copy full SHA for 2804036
1 file changed
crates/aptos-admin-service/src/server/malloc.rs
@@ -18,8 +18,13 @@ unsafe extern "C" fn write_cb(buf: *mut c_void, s: *const c_char) {
18
let out = unsafe { &mut *(buf as *mut Vec<u8>) };
19
let stats_cstr = unsafe { CStr::from_ptr(s).to_bytes() };
20
// We do not want any memory allocation in the callback.
21
- let len = std::cmp::min(out.capacity(), stats_cstr.len());
22
- out.extend_from_slice(&stats_cstr[0..len]);
+ let remaining = out.capacity().saturating_sub(out.len());
+ if remaining == 0 {
23
+ return;
24
+ }
25
+
26
+ let len = std::cmp::min(remaining, stats_cstr.len());
27
+ out.extend_from_slice(&stats_cstr[..len]);
28
}
29
30
fn get_jemalloc_stats_string(max_len: usize) -> anyhow::Result<String> {
0 commit comments