[libc-commits] [libc] [libc] Expand usage of libc null checks. (PR #116262)

Nick Desaulniers via libc-commits libc-commits at lists.llvm.org
Mon Jan 27 08:47:58 PST 2025


================
@@ -16,6 +17,8 @@ namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(int, memcmp,
                    (const void *lhs, const void *rhs, size_t count)) {
+  LIBC_CRASH_ON_NULLPTR(lhs);
+  LIBC_CRASH_ON_NULLPTR(rhs);
----------------
nickdesaulniers wrote:

For some of these `mem` functions from `string.h`, we might only want to do these checks if the `count` parameter is not zero.  I seem to recall that some code bases can expect to call these with nullptr if the `count` is zero.

https://developers.redhat.com/articles/2024/12/11/making-memcpynull-null-0-well-defined

Comes to mind. It links to https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf which has a list of affected functions.  I recommend taking the time to read that blog post and the linked to doc on proposed changes to the C standard.

https://github.com/llvm/llvm-project/pull/116262


More information about the libc-commits mailing list