谁能解释下下面程序为什么报错?

#include <stdio.h>

char *mystrcpy(char *t);

int main()
{
    printf("%s\n", mystrcpy("Hello World"));
    return 0;
}

char *mystrcpy(char *t)
{
    char *s;
    while(*s++ = *t++);
    return s;
}

执行报错:

Segementation fault (core dumped)

while(*s++ = *t++);你没有判断是否到字符串结尾
而且,s也没有分配空间

代码修改如下:

#include <stdio.h>
#include <stdlib.h>
char *mystrcpy(char *t);
int main()
{
    char* p;
    p =  mystrcpy("Hello World");
    printf("%s\n",p);
    free(p);
    return 0;
}
char *mystrcpy(char *t)
{
    char *s;
    int len=0;
    int i = 0;
    while(t[i]) i++;
    len = i;
    i=0;
    s = (char*)malloc(len+1);
    while(t[i])
    {
        s[i] = t[i];
        i++;
    }
    s[i] = 0;
    return s;
}

"Hello World" 是 const char *类型。