Skip to content

Commit 0dab69d

Browse files
committed
Fix obj2txt
1 parent 66b9072 commit 0dab69d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

stdlib/src/ssl.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,16 @@ fn obj2txt(obj: &Asn1ObjectRef, no_name: bool) -> Option<String> {
154154
if buflen == 0 {
155155
return None;
156156
}
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);
157+
let buflen = buflen as usize;
158+
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+
);
159165
assert!(ret >= 0);
166+
buf.set_len(buflen);
160167
String::from_utf8(buf)
161168
.unwrap_or_else(|e| String::from_utf8_lossy(e.as_bytes()).into_owned())
162169
};

0 commit comments

Comments
 (0)