Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upUse a macro to create null-terminated C strings #19916
Comments
|
Hi! If you have any questions regarding this issue, feel free to make a comment here, or ask it in the If you intend to work on this issue, then add |
|
@highfive: assign me |
|
Hey @thiagopnts! Thanks for your interest in working on this issue. It's now assigned to you! |
|
Shouldn't the |
|
We can also use from_bytes_with_nul for some stronger guarantees, but I don't think the overhead is worth it. |
|
Returning a CStr does sound like an improvement. The macro could use CStr::from_bytes_with_nul_unchecked under the hood. |
|
Hmmm... I didn't notice this issue, and wrote a PR #19925 for fixing this... |
|
@thiagopnts Given that the solution in #19925 is safer than what I propose here, we're going to go with that. Sorry for the duplication of effort! |
When we write them by hand (eg.
b"some string\0"), we invariably get them wrong in ways that are tricky to notice (#19915). We should use a macro like this instead:This would allow us to write code like
(c_str!("PEParseDeclarationDeclExpected"), Action::Skip)instead of https://github.com/emilio/servo/blob/d82c54bd3033cc3277ebeb4854739bebe4e20f2f/ports/geckolib/error_reporter.rs#L237. We should be able to clean up all of the uses in that file.No need to run any automated tests; if it builds with
./mach build-geckolib, then it's good enough for a pull request.