-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Consider returning &c_char from CString::as_ptr #16035
Comments
+1 |
We hit this a ton in Servo in this latest rust upgrade, which caused many use after free bugs in otherwise safe code. I think |
cc @aturon |
nominated for 1.0 P-backcompat-libs |
The return type should be Just to clarify, the I'd like to understand better how I could imagine trying to do something more RAII-ish here, and return an object that derefs into Thoughts? |
I believe the idea is that foo(s.as_ref())
// vs
foo(s.as_bytes().as_ptr()) I'd be ok moving this over to |
P-backcompat-libs, but not 1.0: this is in part of the stdlib that is still tagged with |
@alexcrichton Should we repurpose this bug with the new |
This may be less relevant now that the API of |
From IRC today: use std::ffi::CString;
fn main() {
let a = "1";
let b = "2";
let a_ptr = CString::from_slice(a.as_bytes()).as_ptr();
let b_ptr = CString::from_slice(b.as_bytes()).as_ptr();
println!("{:?}", a_ptr);
println!("{:?}", b_ptr);
} |
@alexcrichton I'm not sure I agree, it seems like exactly the same pitfalls are there. I think we should consider adding a method like the one proposed in this issue. |
Nominating for 1.0-beta (P-backcompat-libs, as it already is). |
1.0 beta, P-backcompat-libs, I-needs-decision,. |
Decision: we want to make a change like this, but there are some other ramifications for using We want to introduce some general libraries to cover patterns like that before we make this change. So all told, we're OK stabilzing Closing as WONTFIX (for now). |
I have opened an RFC issue about this issue more broadly which may help alleviate some concerns here as well. |
fix: Fix diagnostics panicking when resolving to different files due to macros Fixes rust-lang/rust-analyzer#14968
This should make it a lot harder to run into the bug mentioned in its documentation (
let p = foo.to_c_str().as_ptr();
).The text was updated successfully, but these errors were encountered: