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

Use Vec::as_mut_ptr to obtain a buffer for __system_property_get. #1

Merged
merged 1 commit into from
Jun 29, 2022

Conversation

jimblandy
Copy link
Contributor

Use the idiom recommended by the Nomicon for allocating a buffer into which C code will write data:

https://doc.rust-lang.org/nomicon/ffi.html#creating-a-safe-interface

The current code is almost certainly fine in practice, but it doesn't follow the letter of the law. The documentation for CString::into_raw says:

The pointer which this function returns must be returned to Rust and reconstituted using CString::from_raw to be properly deallocated.

https://doc.rust-lang.org/std/ffi/struct.CString.html#method.into_raw

Use the idiom recommended by the Nomicon for allocating a buffer into
which C code will write data:

https://doc.rust-lang.org/nomicon/ffi.html#creating-a-safe-interface

The current code is almost certainly fine in practice, but it doesn't
follow the letter of the law. The documentation for
`CString::into_raw` says:

    The pointer which this function returns must be returned to Rust and
    reconstituted using `CString::from_raw` to be properly deallocated.

https://doc.rust-lang.org/std/ffi/struct.CString.html#method.into_raw
@jimblandy
Copy link
Contributor Author

I haven't tested this code - I haven't set up an android development environment yet.

@nical
Copy link
Owner

nical commented Jun 29, 2022

LGTM, tested on my phone.

@nical nical merged commit d4c8a1f into nical:main Jun 29, 2022
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.

2 participants