0
0
mirror of https://github.com/cjdelisle/cjdns synced 2025-10-06 00:32:50 +02:00

benc: Strings must be zero padded

This commit is contained in:
Caleb James DeLisle
2024-10-01 16:56:25 +02:00
parent 8ffca94c6e
commit 1477ff993a

View File

@@ -47,10 +47,13 @@ pub fn list_to_c<'a>(alloc: *mut Allocator_t, v: &Vec<Value<'a>>) -> *mut List_t
pub fn string_to_c<'a>(alloc: *mut Allocator_t, v: impl Into<&'a[u8]>) -> *mut String_t {
let v: &'a[u8] = v.into();
let bytes = allocator::adopt(alloc, Vec::from(v));
let mut v = Vec::from(v);
let len = v.len();
v.push(0);
let bytes = allocator::adopt(alloc, v);
let bytes = unsafe { (*bytes)[..].as_mut_ptr() };
allocator::adopt(alloc, String_t{
len: v.len(),
len,
bytes: bytes as _,
})
}