We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 66b9072 commit 0dab69dCopy full SHA for 0dab69d
stdlib/src/ssl.rs
@@ -154,9 +154,16 @@ fn obj2txt(obj: &Asn1ObjectRef, no_name: bool) -> Option<String> {
154
if buflen == 0 {
155
return None;
156
}
157
- let mut buf = vec![0u8; buflen as usize];
158
- let ret = sys::OBJ_obj2txt(buf.as_mut_ptr() as *mut libc::c_char, buflen, ptr, no_name);
+ let buflen = buflen as usize;
+ let mut buf = Vec::<u8>::with_capacity(buflen + 1);
159
+ let ret = sys::OBJ_obj2txt(
160
+ buf.as_mut_ptr() as *mut libc::c_char,
161
+ buf.capacity() as _,
162
+ ptr,
163
+ no_name,
164
+ );
165
assert!(ret >= 0);
166
+ buf.set_len(buflen);
167
String::from_utf8(buf)
168
.unwrap_or_else(|e| String::from_utf8_lossy(e.as_bytes()).into_owned())
169
};
0 commit comments