strlen not checking for NULL

后端 未结 6 1244
小蘑菇
小蘑菇 2020-12-01 07:52

Why is strlen() not checking for NULL?

if I do strlen(NULL), the program segmentation faults.

Trying to understand the rationale be

6条回答
  •  不知归路
    2020-12-01 08:31

    size_t strlen ( const char * str );
    

    http://www.cplusplus.com/reference/clibrary/cstring/strlen/

    Strlen takes a pointer to a character array as a parameter, null is not a valid argument to this function.

提交回复
热议问题