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

[C++] Better handling mem* api that behave sanely on NULL input #44814

Open
mapleFU opened this issue Nov 22, 2024 · 2 comments
Open

[C++] Better handling mem* api that behave sanely on NULL input #44814

mapleFU opened this issue Nov 22, 2024 · 2 comments

Comments

@mapleFU
Copy link
Member

mapleFU commented Nov 22, 2024

          I think we take a systematic approach to this and make wrappers to `mem*` functions that behave sanely on `NULL` input.

This article [1] discusses the issue in detail and points to approaches taken by projects like boringssl. [2] There is also a proposal from prolific LLVM contributors for fixing this at the C standard level. [3]

[1] https://davidben.net/2024/01/15/empty-slices.html
[2] https://boringssl.googlesource.com/boringssl/+/17cf2cb1d226b0ba2401304242df7ddd3b6f1ff2%5E%21/
[3] https://docs.google.com/document/d/1guH_HgibKrX7t9JfKGfWX2UCPyZOTLsnRfR6UleD1F8/edit?tab=t.0

Originally posted by @felipecrv in #44794 (comment)

@felipecrv
Copy link
Contributor

felipecrv commented Nov 22, 2024

Make the wrappers inlineable (defined in a header) so the checks can be elided by the compiler when it can be proven at the callsite that the pointer is not null already.

@felipecrv
Copy link
Contributor

Another idea (suggest the wrappers with clang-tidy warnings): #44794 (comment)

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

2 participants