On 04/09/2020 20:21, Florian Weimer wrote: > * Jonny Grant: > >> Hello >> >> https://man7.org/linux/man-pages/man3/strlen.3.html >> >> Is it possible to clarify :- >> >> * glibc will SIGSEGV if 's' is NULL >> * there are no ERROR returns > > That would be misleading. Whether strlen (NULL) is undefined also > depends on the compiler. They know that the argument cannot be zero > and optimize accordingly. > Hi, Do you know a compiler that has a different behaviour? I only tested gcc and clang. How would a compiler optimise? The header has non-null attribute for the compiler (ie gcc) to use to give a nice warning str.c:6:8: warning: null argument where non-null required (argument 1) [-Wnonnull] 6 | return strlen(NULL); However, if the implementation gets NULL it still crashes. I was using -fno-builtin-strlen so it was glibc, but the __builtin_strlen ha SEGV just like glibc clang is the same as gcc. So it feels like it's pretty clear, there is no NULL check, can this be documented? Jonny