@@ -9,7 +9,7 @@ use std::{
9
9
ptr, slice,
10
10
} ;
11
11
12
- use log:: { error, trace} ;
12
+ use log:: { error, trace, warn } ;
13
13
use thiserror:: Error ;
14
14
15
15
#[ derive( Error , Debug ) ]
@@ -60,17 +60,24 @@ unsafe fn from_addr(count: usize, ptr: *const *const c_char) -> Result<MemInfo,
60
60
let mut saved: Vec < CString > = Vec :: with_capacity ( count) ;
61
61
for i in 0 ..count {
62
62
let cstr_ptr = * ptr. add ( i) ;
63
+ trace ! (
64
+ "string[{i}] ptr info: current ptr={:?}, point to={cstr_ptr:?}" ,
65
+ ptr. add( i)
66
+ ) ;
67
+ if cstr_ptr. is_null ( ) {
68
+ warn ! ( "the string[{i}] is null, pls check" ) ;
69
+ break ;
70
+ }
63
71
let cstr_len = CStr :: from_ptr ( cstr_ptr) . to_bytes_with_nul ( ) . len ( ) ;
64
72
saved. push ( CStr :: from_ptr ( cstr_ptr) . into ( ) ) ;
65
73
// Decide elsewhere whether to exclude nul.
66
74
byte_len += cstr_len;
67
75
68
- trace ! ( "string[{i}] collect: recorded len={byte_len}, ptr={cstr_ptr:?}, string len={cstr_len}, next ptr={:?}" ,
76
+ trace ! (
77
+ "string[{i}] collect: recorded len={byte_len}, start addr={cstr_ptr:?}, len={cstr_len}, end addr (with null)={:?}" ,
69
78
cstr_ptr. add( cstr_len - 1 )
70
79
) ;
71
80
if i == count - 1 {
72
- // It is assumed that arg/environ must never have an element
73
- // of length 0, otherwise unpredictable results would occur.
74
81
// Perhaps it would be better to add 1 byte manually when
75
82
// calculating the length.
76
83
// Avoid overstepping the bounds.
0 commit comments