Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark packDouble2x32 function as unsafe #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kitcatier
Copy link

@kitcatier kitcatier commented Mar 19, 2023

glm-rs/src/builtin/pack.rs

Lines 259 to 262 in df5a989

pub fn packDouble2x32(v: UVec2) -> f64 {
let f: &f64 = unsafe { mem::transmute(&v) };
*f
}

Hello, the unsafe function called needs to ensure that the parameter must be:https://doc.rust-lang.org/std/mem/fn.transmute.html

It uses the mem::transmute function, which can lead to undefined behavior if used incorrectly. The mem::transmute function is used to reinterpret the memory of one type as another type, which can be dangerous if the types have different sizes or alignment requirements. Therefore, any function that uses mem::transmute must be marked as unsafe to indicate that the caller must take care to ensure that it is used correctly. The developer who calls the uninit_vector function may not notice this safety requirement.

Marking them unsafe also means that callers must make sure they know what they're doing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant