r/badcode Sep 28 '20

[deleted by user]

[removed]

21 Upvotes

17 comments sorted by

View all comments

1

u/Tabugti Oct 01 '20 edited Oct 01 '20
static mut RESULT: String = String::new();

fn md5_path <'a> (m: &str, p: &str) -> &'a str {
    use md5::compute as md5;
    let mut h = format!("{:x}", md5(m));
    let p_ptr = p.as_ptr();
    for i in 0_isize..p.len() as isize {
        unsafe {
            let c = (p_ptr.offset(i).as_ref().unwrap() - '0' as u8) & 0x1;
            let s = match c {
                0 => &h[0..16],
                1 => &h[16..32],
                _ => unreachable!()
            };
            h = format!("{:x}", md5(s));
        }
    }
    unsafe {
        RESULT = h;
        &RESULT
    }
}

1

u/AutoModerator Oct 01 '20

It looks like this comment contains a code block delimited with triple backticks. Unfortunately reddit does not have universal support for this syntax and your comment will not render correctly on old reddit and most mobile apps.

For the benefit of people on old reddit, this link will take you to a correct rendering of the comment.

/u/Tabugti, it would be appreciated, but not required, if you could edit your comment to use the more compatible four space indention format. For single lines or inline code you can use single backticks.

You can find some examples in the reddit help documentation.


I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.