22

不定项选择题 22 /101

如下程序用于输出“Welcome to Huawei Test”,请指出其中潜在风险的位置()
char * GetWelcome(void){
    char * pcWelcome;
    char * pcNewWelcome;
    pcWelcome = "Welcome to Huawei Test";
    pcNewWelcome = (char *)malloc(strlen(pcWelcome));    //1
    if(NULL == pcNewWelcome){
        return NULL;        //2
    }
    strcpy(pcNewWelcome, pcWelcome);    //3
    return pcNewWelcome;            //4
}
printf("%s\n", GetWelcome());

参考答案

1
2
3
4