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

Nick Desaulniers via libc-commits libc-commits at lists.llvm.org
Mon Feb 10 10:58:34 PST 2025


================
@@ -9,12 +9,15 @@
 #include "src/string/strsep.h"
 
 #include "src/__support/macros/config.h"
+#include "src/__support/macros/null_check.h"
 #include "src/string/string_utils.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(char *, strsep,
                    (char **__restrict stringp, const char *__restrict delim)) {
+  LIBC_CRASH_ON_NULLPTR(stringp);
+  LIBC_CRASH_ON_NULLPTR(delim);
----------------
nickdesaulniers wrote:

I'm saying:
```c
LIBC_CRASH_ON_NULLPTR(stringp);
if (!*stringp)
    return nullptr;
LIBC_CRASH_ON_NULLPTR(delim);
```

`man 3 strsep` says:

> If  *stringp is NULL, the strsep() function returns NULL and does nothing else.

So in that case, if `stringp` is not NULL and `*stringp` _is_ NULL, we should not crash based on the value of `delim`.

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


More information about the libc-commits mailing list