@@ -44,13 +44,14 @@ pub(super) struct MapsEntry {
44
44
}
45
45
46
46
pub ( super ) fn parse_maps ( ) -> Result < Vec < MapsEntry > , & ' static str > {
47
- let mut v = Vec :: new ( ) ;
48
47
let mut proc_self_maps =
49
48
File :: open ( "/proc/self/maps" ) . map_err ( |_| "Couldn't open /proc/self/maps" ) ?;
50
49
let mut buf = String :: new ( ) ;
51
50
let _bytes_read = proc_self_maps
52
51
. read_to_string ( & mut buf)
53
52
. map_err ( |_| "Couldn't read /proc/self/maps" ) ?;
53
+
54
+ let mut v = Vec :: new ( ) ;
54
55
for line in buf. lines ( ) {
55
56
v. push ( line. parse ( ) ?) ;
56
57
}
@@ -84,41 +85,50 @@ impl FromStr for MapsEntry {
84
85
// Note that paths may contain spaces, so we can't use `str::split` for parsing (until
85
86
// Split::remainder is stabilized #77998).
86
87
fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
88
+ fn error ( msg : & str ) -> & str {
89
+ if cfg ! ( debug_assertions) {
90
+ msg
91
+ } else {
92
+ "invalid map entry"
93
+ }
94
+ }
95
+
96
+
87
97
let ( range_str, s) = s. trim_start ( ) . split_once ( ' ' ) . unwrap_or ( ( s, "" ) ) ;
88
98
if range_str. is_empty ( ) {
89
- return Err ( "Couldn't find address" ) ;
99
+ return Err ( error ( "Couldn't find address" ) ) ;
90
100
}
91
101
92
102
let ( perms_str, s) = s. trim_start ( ) . split_once ( ' ' ) . unwrap_or ( ( s, "" ) ) ;
93
103
if perms_str. is_empty ( ) {
94
- return Err ( "Couldn't find permissions" ) ;
104
+ return Err ( error ( "Couldn't find permissions" ) ) ;
95
105
}
96
106
97
107
let ( offset_str, s) = s. trim_start ( ) . split_once ( ' ' ) . unwrap_or ( ( s, "" ) ) ;
98
108
if offset_str. is_empty ( ) {
99
- return Err ( "Couldn't find offset" ) ;
109
+ return Err ( error ( "Couldn't find offset" ) ) ;
100
110
}
101
111
102
112
let ( dev_str, s) = s. trim_start ( ) . split_once ( ' ' ) . unwrap_or ( ( s, "" ) ) ;
103
113
if dev_str. is_empty ( ) {
104
- return Err ( "Couldn't find dev" ) ;
114
+ return Err ( error ( "Couldn't find dev" ) ) ;
105
115
}
106
116
107
117
let ( inode_str, s) = s. trim_start ( ) . split_once ( ' ' ) . unwrap_or ( ( s, "" ) ) ;
108
118
if inode_str. is_empty ( ) {
109
- return Err ( "Couldn't find inode" ) ;
119
+ return Err ( error ( "Couldn't find inode" ) ) ;
110
120
}
111
121
112
122
// Pathname may be omitted in which case it will be empty
113
123
let pathname_str = s. trim_start ( ) ;
114
124
115
- let hex = |s| usize:: from_str_radix ( s, 16 ) . map_err ( |_| "Couldn't parse hex number" ) ;
116
- let hex64 = |s| u64:: from_str_radix ( s, 16 ) . map_err ( |_| "Couldn't parse hex number" ) ;
125
+ let hex = |s| usize:: from_str_radix ( s, 16 ) . map_err ( |_| error ( "Couldn't parse hex number" ) ) ;
126
+ let hex64 = |s| u64:: from_str_radix ( s, 16 ) . map_err ( |_| error ( "Couldn't parse hex number" ) ) ;
117
127
118
128
let address = if let Some ( ( start, limit) ) = range_str. split_once ( '-' ) {
119
129
( hex ( start) ?, hex ( limit) ?)
120
130
} else {
121
- return Err ( "Couldn't parse address range" ) ;
131
+ return Err ( error ( "Couldn't parse address range" ) ) ;
122
132
} ;
123
133
124
134
let offset = hex64 ( offset_str) ?;
0 commit comments