#odd #unsafe #bug #platform #compiler #transmute #cve-rs

odd_is_odd

A very (not) safe library to check if a number is odd. Based on cve-rs.

5 releases

0.2.1 Mar 19, 2024
0.2.0 Mar 2, 2024
0.1.2 Mar 2, 2024
0.1.1 Mar 2, 2024
0.1.0 Mar 2, 2024

#4 in #odd

Download history 239/week @ 2024-02-27 9/week @ 2024-03-05 113/week @ 2024-03-12 136/week @ 2024-03-19 10/week @ 2024-03-26 33/week @ 2024-04-02

296 downloads per month

Unlicense

5KB
64 lines

A very (not) safe library to check if a number is odd. Abuses the same bugs and tricks in cve-rs to transmute the given i8 to a bool without using unsafe.

This relies on a compiler bug, almost certainly doesn't work on all platforms, and is possibly the least reasonable is_odd function you could imagine.

See https://www.youtube.com/watch?v=vfMpIsJwpjU&list=PLzl2iy0KCGD6N93omgPEjgakVYA5t-1oV

Example:

use odd_is_odd::is_odd;
fn main() {
    if (is_odd(69)) {
        println!("on our way to hundreds of thousands of downloads a week!");
    } else {
        println!("who could have guessed, the sketchy library is sketchy");
        assert!(false);
    }
}

lib.rs:

A very (not) safe library to check if a number is odd. Abuses the same bugs and tricks in cve-rs to transmute the given i8`` to a boolwithout usingunsafe`.

This relies on a compiler bug, almost certainly doesn't work on all platforms, and is possibly the least reasonable is_odd function you could imagine.

See https://www.youtube.com/watch?v=vfMpIsJwpjU&list=PLzl2iy0KCGD6N93omgPEjgakVYA5t-1oV

Example

use odd_is_odd::is_odd;
fn main() {
    if (is_odd(69)) {
        println!("on our way to hundreds of thousands of downloads a week!");
    } else {
        println!("who could have guessed, the sketchy library is sketchy");
        assert!(false);
    }
}

No runtime deps