gentoo90 / winreg-rs

Rust bindings to MS Windows Registry API
MIT License
168 stars 36 forks source link

Garbage data appears in Strings after manipulation #71

Closed Delphinidae84 closed 6 days ago

Delphinidae84 commented 1 week ago

I have a rather simple function which reads values by key_path and value_name.

pub fn read_reg_key(key_path: &str, value_name: &str) -> Result<String, DirError> {
    let hklm = RegKey::predef(HKEY_LOCAL_MACHINE);

    let sub_key = match hklm.open_subkey(key_path) {
        Ok(sk) => sk,
        Err(_err) => return Err(DirError::GeneralFail),
    };

    match sub_key.get_value(value_name) {
        Ok(val) => Ok(val),
        Err(_err) => Err(DirError::GeneralFail),
    }
}

The content and length of the output looks correct:

grafik

But as soon as I manipulate the string in any way (for example value.push('/')), garbage appears to be appended to the original string.

grafik

I tried to limit the string's by its len which is correct in the beginning:

value = value.chars().take(value.len()).collect();

But this also seems to append garbage to the string itself. Any idea what might be causing this behaviour?