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

Question about Box from null #1452

Open
Nugine opened this issue Mar 1, 2025 · 0 comments
Open

Question about Box from null #1452

Nugine opened this issue Mar 1, 2025 · 0 comments

Comments

@Nugine
Copy link

Nugine commented Mar 1, 2025

For example, I see a function that is exported via extern "Rust" in cxx::brige. (deepseek-ai/3FS#11)

fn create(path: &str, create: bool, prefix_len: usize, error: Pin<&mut CxxString>) -> Box<Engine> {
    let config = EngineConfig {
        path: PathBuf::from(path),
        create,
        prefix_len,
    };
    match Engine::open(&config) {
        Ok(engine) => Box::new(engine),
        Err(e) => {
            error.push_str(&e.to_string());
            unsafe { Box::from_raw(std::ptr::null_mut()) }
        }
    }
}

unsafe { Box::from_raw(std::ptr::null_mut()) }

Is this line a UB even if the Box is exported to C++ side?

And if it is UB, what is the recommanded way to fix? Raw pointer?

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

No branches or pull requests

1 participant