strcpy-越界-覆盖

来源:互联网 发布:移动通信网络结构图 编辑:程序博客网 时间:2024/05/18 06:22
#include <string.h>#include <stdlib.h>#include <stdio.h>int main(){    char *p = NULL;    p = (char *)malloc(10);    memcpy(p,"1234567",strlen("1234567"));    printf("before p = %s\n", p);    printf("p=%p\np+1=%p\n",p,p+1);    strcpy(p+1,p);//这重叠了    printf("after p = %s\n", p);    free(p);    return 0;}/****** result *****//*before p=1234567p=00490FD8p+1=00490FD9after p=11234467*/

原创粉丝点击