[][src]Function tikv_jemalloc_ctl::raw::update_str

pub unsafe fn update_str(
    name: &[u8],
    value: &'static [u8]
) -> Result<&'static [u8]>

Uses the null-terminated string name as key to the MALLCTL NAMESPACE and writes its value returning its previous value.

Safety

This function is unsafe because if the key does not return a pointer to a null-terminated string the behavior is undefined.

For example, a key for a u64 value can be used to read a pointer on 64-bit platform, where this pointer will point to the address denoted by the u64s representation. Also, a key to a *mut extent_hooks_t will return a pointer that will not point to a null-terminated string.

This function needs to compute the length of the string by looking for the null-terminator: \0. This requires reading the memory behind the pointer.

If the pointer is invalid (e.g. because it was converted from a u64 that does not represent a valid address), reading the string to look for \0 will dereference a non-dereferenceable pointer, which is undefined behavior.

If the pointer is valid but it does not point to a null-terminated string, looking for \0 will read garbage and might end up reading out-of-bounds, which is undefined behavior.