Is strlen on a string with uninitialized values undefined behavior?

后端 未结 4 1905
暖寄归人
暖寄归人 2020-12-19 06:23

strlen returns the number of characters that precede the terminating null character. An implementation of strlen might look like this:



        
4条回答
  •  不知归路
    2020-12-19 07:12

    Yes, it's undefined behaviour. From the draft C11 standard, §J.2 "Undefined behavior":

    The behavior is undefined in the following circumstances:

    ...

    The value of an object with automatic storage duration is used while it is indeterminate.

提交回复
热议问题