Is the function strcpy always dangerous?

后端 未结 9 2347
不知归路
不知归路 2020-12-06 08:22

Are functions like strcpy, gets, etc. always dangerous? What if I write a code like this:

int main(void)
{

char *str1 = \"abcdefghijklmnop\";
char *str2 = m         


        
9条回答
  •  执笔经年
    2020-12-06 09:03

    Your code is not safe. The return value of malloc is unchecked, if it fails and returns 0 the strcpy will give undefined behavior.

    Besides that, I see no problem other than that the example basically does not do anything.

提交回复
热议问题